Skip to content

Instantly share code, notes, and snippets.

@yoctozepto
Last active February 1, 2021 09:02
Show Gist options
  • Save yoctozepto/4408d70fee31ac3ba9d8a6491c370dfe to your computer and use it in GitHub Desktop.
Save yoctozepto/4408d70fee31ac3ba9d8a6491c370dfe to your computer and use it in GitHub Desktop.
ansible#22579 workaround
---
### 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 }}"
@markgoddard
Copy link

markgoddard commented Feb 1, 2021

I think you can to map(attribute='item.key')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment