Last active
August 24, 2024 09:23
-
-
Save halberom/86914f86c0c33a65afe6 to your computer and use it in GitHub Desktop.
ansible - handler with_items
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
- name: restart stunnel services | |
service: name={{ item.item }} state=restarted | |
with_items: stunnel_config_result.results | |
when: item | changed |
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
- name: Configure stunnel | |
template: src=stunnel.conf.j2 | |
dest='/etc/stunnel/stunnel-{{ item.name }}.conf' | |
owner=root | |
group=root | |
mode=0644 | |
when: item.state == 'present' | |
with_items: stunnel_config | |
tags: ['f'] | |
register: stunnel_config_result | |
notify: | |
- restart stunnel | |
Thanks, this was helpful. But...
I would add that this case is not correct for multi-notifications in tasks. Multi-notifications in tasks rewrite stunnel_config_result variable and handler dirive last set items from stunnel_config_result and ignore rewrited values!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this was helpful. One thing to mention for other readers is that in modern ansible versions
with_items
with a variable needs to be a Jinja expression, e.g.with_items: "{{ stunnel_config_result.results }}"