|
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 | + |
35 | 44 | - name: Get existing lifecycle policy JSON for {{ service_id }}_{{ item }} |
36 | 45 | ansible.builtin.command: > |
37 | 46 | {{ aws_cmd }} ecr get-lifecycle-policy |
|
42 | 51 | failed_when: false |
43 | 52 | changed_when: false |
44 | 53 |
|
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 |
46 | 64 | 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 |
49 | 67 |
|
50 | | -- name: Read lifecycle policy from the local file |
| 68 | +- name: Read lifecycle policy from the shared file |
51 | 69 | ansible.builtin.slurp: |
52 | | - src: "{{ role_path }}/files/ecr_lifecycle.json" |
| 70 | + src: "{{ playbook_dir }}/../../ecr-lifecycle/ecr_lifecycle.json" |
53 | 71 | register: desired_policy_raw |
54 | 72 |
|
55 | 73 | - name: Decode lifecycle policy file |
|
60 | 78 | ansible.builtin.command: > |
61 | 79 | {{ aws_cmd }} ecr put-lifecycle-policy |
62 | 80 | --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 |
64 | 82 | when: |
65 | 83 | - existing_policy_json != desired_policy_json |
66 | 84 | - env != "prod" or prod_lifecycle_update_allowed |
0 commit comments