Skip to content

Instantly share code, notes, and snippets.

@halberom
Last active May 6, 2019 09:07
Show Gist options
  • Save halberom/86914f86c0c33a65afe6 to your computer and use it in GitHub Desktop.
Save halberom/86914f86c0c33a65afe6 to your computer and use it in GitHub Desktop.
ansible - handler with_items
- name: restart stunnel services
service: name={{ item.item }} state=restarted
with_items: stunnel_config_result.results
when: item | changed
- 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
@baughj
Copy link

baughj commented Aug 24, 2018

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 }}"

@TipDev
Copy link

TipDev commented May 6, 2019

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