Skip to content

Commit e323623

Browse files
committed
ecr lifecycle policy null values
1 parent 8098301 commit e323623

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

ansible/roles/build-ecs-proxies/tasks/build-container.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232
cmd: "docker push {{ image_name }}"
3333
when: build_result.rc == 0
3434

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+
3544
- name: Get existing lifecycle policy JSON for {{ service_id }}_{{ item }}
3645
ansible.builtin.command: >
3746
{{ aws_cmd }} ecr get-lifecycle-policy
@@ -42,14 +51,23 @@
4251
failed_when: false
4352
changed_when: false
4453

45-
- name: Parse existing lifecycle policy JSON
54+
- name: Parse existing lifecycle policy JSON if present
55+
set_fact:
56+
existing_policy_json: "{{ existing_policy_raw.stdout | from_json }}"
57+
when:
58+
- existing_policy_raw.stdout is defined
59+
- existing_policy_raw.stdout != ""
60+
- existing_policy_raw.stdout != "None"
61+
- existing_policy_raw.stdout != "null"
62+
63+
- name: Ensure existing_policy_json always exists
4664
set_fact:
47-
existing_policy_json: "{{ existing_policy_raw.stdout | default('{}') | from_json }}"
48-
when: existing_policy_raw.stdout != ""
65+
existing_policy_json: {}
66+
when: existing_policy_json is not defined
4967

50-
- name: Read lifecycle policy from the local file
68+
- name: Read lifecycle policy from the shared file
5169
ansible.builtin.slurp:
52-
src: "{{ role_path }}/files/ecr_lifecycle.json"
70+
src: "{{ playbook_dir }}/../../ecr-lifecycle/ecr_lifecycle.json"
5371
register: desired_policy_raw
5472

5573
- name: Decode lifecycle policy file
@@ -60,7 +78,7 @@
6078
ansible.builtin.command: >
6179
{{ aws_cmd }} ecr put-lifecycle-policy
6280
--repository-name {{ service_id }}_{{ item }}
63-
--lifecycle-policy-text file://{{ playbook_dir }}/../../common/a-management-utils-3/ecr-lifecycle/ecr_lifecycle.json
81+
--lifecycle-policy-text file://{{ playbook_dir }}/../../ecr-lifecycle/ecr_lifecycle.json
6482
when:
6583
- existing_policy_json != desired_policy_json
6684
- env != "prod" or prod_lifecycle_update_allowed

0 commit comments

Comments
 (0)