|
32 | 32 | cmd: "docker push {{ image_name }}" |
33 | 33 | when: build_result.rc == 0 |
34 | 34 |
|
35 | | -- name: List contents of playbook_dir |
36 | | - ansible.builtin.command: > |
37 | | - ls -al {{ playbook_dir }} |
38 | | - register: ls_playbook |
39 | | - |
40 | | -- name: Show playbook_dir contents |
41 | | - debug: |
42 | | - var: ls_playbook.stdout |
43 | | - |
44 | 35 | - name: Get existing lifecycle policy JSON for {{ service_id }}_{{ item }} |
45 | 36 | ansible.builtin.command: > |
46 | 37 | {{ aws_cmd }} ecr get-lifecycle-policy |
|
65 | 56 | existing_policy_json: {} |
66 | 57 | when: existing_policy_json is not defined |
67 | 58 |
|
68 | | -- name: Read lifecycle policy from the shared file |
69 | | - ansible.builtin.slurp: |
70 | | - src: "{{ playbook_dir }}/../ecr-lifecycle/ecr_lifecycle.json" |
71 | | - register: desired_policy_raw |
72 | | - |
73 | | -- name: Decode lifecycle policy file |
74 | | - set_fact: |
75 | | - desired_policy_json: "{{ desired_policy_raw.content | b64decode | from_json }}" |
76 | | - |
77 | | -- name: Apply lifecycle policy to ecr {{ service_id }}_{{ item }} if different |
78 | | - ansible.builtin.command: > |
79 | | - {{ aws_cmd }} ecr put-lifecycle-policy |
80 | | - --repository-name {{ service_id }}_{{ item }} |
81 | | - --lifecycle-policy-text file://{{ playbook_dir }}/../ecr-lifecycle/ecr_lifecycle.json |
82 | | - when: |
83 | | - - existing_policy_json != desired_policy_json- name: Get existing lifecycle policy JSON for {{ service_id }}_{{ item }} |
84 | | - ansible.builtin.command: > |
85 | | - {{ aws_cmd }} ecr get-lifecycle-policy |
86 | | - --repository-name {{ service_id }}_{{ item }} |
87 | | - --query 'lifecyclePolicyText' |
88 | | - --output text |
89 | | - register: existing_policy_raw |
90 | | - failed_when: false |
91 | | - changed_when: false |
92 | | - |
93 | | -- name: Parse existing lifecycle policy JSON if present |
94 | | - set_fact: |
95 | | - existing_policy_json: "{{ existing_policy_raw.stdout | from_json }}" |
96 | | - when: |
97 | | - - existing_policy_raw.stdout is defined |
98 | | - - existing_policy_raw.stdout != "" |
99 | | - - existing_policy_raw.stdout != "None" |
100 | | - - existing_policy_raw.stdout != "null" |
101 | | - |
102 | | -- name: Ensure existing_policy_json always exists |
103 | | - set_fact: |
104 | | - existing_policy_json: {} |
105 | | - when: existing_policy_json is not defined |
106 | | - |
107 | 59 | - name: Read lifecycle policy from the shared file |
108 | 60 | ansible.builtin.slurp: |
109 | 61 | src: "{{ playbook_dir }}/ecr-lifecycle/ecr_lifecycle.json" |
|
0 commit comments