Last active
November 20, 2024 10:52
-
-
Save yoctozepto/4408d70fee31ac3ba9d8a6491c370dfe to your computer and use it in GitHub Desktop.
ansible#22579 workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
### For details see https://github.com/ansible/ansible/issues/22579 | |
### BEFORE | |
--- | |
- name: Check freezer containers | |
become: true | |
kolla_docker: | |
action: "compare_container" | |
common_options: "{{ docker_common_options }}" | |
name: "{{ item.value.container_name }}" | |
image: "{{ item.value.image }}" | |
volumes: "{{ item.value.volumes | reject('equalto', '') | list }}" | |
dimensions: "{{ item.value.dimensions }}" | |
when: | |
- inventory_hostname in groups[item.value.group] | |
- item.value.enabled | bool | |
with_dict: "{{ freezer_services }}" | |
notify: | |
- "Restart {{ item.key }} container" | |
### AFTER (`notify` replaced by `register` and another task introduced) | |
--- | |
- name: Check freezer containers | |
become: true | |
kolla_docker: | |
action: "compare_container" | |
common_options: "{{ docker_common_options }}" | |
name: "{{ item.value.container_name }}" | |
image: "{{ item.value.image }}" | |
volumes: "{{ item.value.volumes | reject('equalto', '') | list }}" | |
dimensions: "{{ item.value.dimensions }}" | |
when: | |
- inventory_hostname in groups[item.value.group] | |
- item.value.enabled | bool | |
with_dict: "{{ freezer_services }}" | |
register: container_check | |
# NOTE(yoctozepto): Must be a separate task because one cannot see the whole | |
# result in the previous task and Ansible has a quirk regarding notifiers. | |
# For details see https://github.com/ansible/ansible/issues/22579 | |
- name: Notify freezer containers for restart | |
debug: | |
msg: Ansible is quirky | |
changed_when: container_check is changed | |
notify: "{{ container_check.results | select('changed') | map(attribute='item') | map(attribute='key') | map('regex_replace', '^(.*)$', 'Restart \\1 container') | list }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you can to map(attribute='item.key')