|
31 | 31 | ansible.builtin.command: |
32 | 32 | cmd: "docker push {{ image_name }}" |
33 | 33 | when: build_result.rc == 0 |
34 | | - |
35 | | -- name: Get existing lifecycle policy JSON for {{ service_id }}_{{ item }} |
36 | | - ansible.builtin.command: > |
37 | | - {{ aws_cmd }} ecr get-lifecycle-policy |
38 | | - --repository-name {{ service_id }}_{{ item }} |
39 | | - --query 'lifecyclePolicyText' |
40 | | - --output text |
41 | | - register: existing_policy_raw |
42 | | - failed_when: false |
43 | | - changed_when: false |
44 | | - |
45 | | -- name: Parse existing lifecycle policy JSON if present |
46 | | - set_fact: |
47 | | - existing_policy_json: "{{ existing_policy_raw.stdout | from_json }}" |
48 | | - when: |
49 | | - - existing_policy_raw.stdout is defined |
50 | | - - existing_policy_raw.stdout != "" |
51 | | - - existing_policy_raw.stdout != "None" |
52 | | - - existing_policy_raw.stdout != "null" |
53 | | - |
54 | | -- name: Ensure existing_policy_json always exists |
55 | | - set_fact: |
56 | | - existing_policy_json: {} |
57 | | - when: existing_policy_json is not defined |
58 | | - |
59 | | -- name: Read lifecycle policy from the shared file |
60 | | - ansible.builtin.slurp: |
61 | | - src: "{{ playbook_dir }}/ecr-lifecycle/ecr_lifecycle.json" |
62 | | - register: desired_policy_raw |
63 | | - |
64 | | -- name: Debug raw slurp output |
65 | | - debug: |
66 | | - var: desired_policy_raw |
67 | | - |
68 | | -- name: Show decoded lifecycle policy content |
69 | | - debug: |
70 | | - msg: "{{ desired_policy_raw.content | b64decode }}" |
71 | | - |
72 | | -- name: Decode lifecycle policy file |
73 | | - set_fact: |
74 | | - desired_policy_json: "{{ desired_policy_raw.content | b64decode | from_json }}" |
75 | | - |
76 | | -- name: Apply lifecycle policy to ecr {{ service_id }}_{{ item }} if different |
77 | | - ansible.builtin.command: > |
78 | | - {{ aws_cmd }} ecr put-lifecycle-policy |
79 | | - --repository-name {{ service_id }}_{{ item }} |
80 | | - --lifecycle-policy-text '{{ desired_policy_json | to_json }}' |
81 | | - when: |
82 | | - - existing_policy_json != desired_policy_json |
83 | | - |
0 commit comments