Notify based on with_items variable

260 views
Skip to first unread message

Paul Wolstenholme

unread,
Sep 24, 2014, 4:57:15 PM9/24/14
to ansible...@googlegroups.com
I'm using the template module and would like loop through a bunch of templates for configuration files and execute and handler if need be. I tried the following. And, it failed. I thought it would be cool to avoid descrete template plays for each service.

- name: Push NRPE configuration files
  template: 
    src={{item.j2}} 
    dest={{item.dest}} 
    mode={{item.mode}}
    backup=yes
  register: nrpe    
  notify: {{item.handler}}
  with_items:
    - { j2: "smartos_setup.sh.j2", dest: "{{smartos_custom}}/share/svc/smartos_setup.sh", mode: '0755', handler: 'setup-reload' }
    - { j2: "nrpe.cfg.j2", dest: "{{smartos_custom}}/etc/nrpe.cfg", mode: '0644', handler: 'nrpe-reload' }    
  tags: smartos_global

Result:

ok: [smartos01] => (item={'dest': u'/opt/custom/smf/nrpe/manifest.xml', 'handler': 'nrpe-reload', 'mode': '0644', 'j2': 'nrpe-manifest.xml.j2'})
changed: [smartos01] => (item={'dest': u'/opt/custom/etc/nrpe.cfg', 'handler': 'nrpe-reload', 'mode': '0644', 'j2': 'nrpe.cfg.j2'})
ERROR: change handler ({{ item.handler }}) is not defined

Michael DeHaan

unread,
Sep 24, 2014, 5:46:00 PM9/24/14
to ansible...@googlegroups.com
Hi Paul,

The way notify works is if any of the tasks is changed (when looping) it will fire the notify.

It does not fire per task.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/de933ec7-bc71-4e56-b3db-55cf85a43409%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul Wolstenholme

unread,
Sep 24, 2014, 6:51:18 PM9/24/14
to ansible...@googlegroups.com
Hi Michael,

Thanks for clarifying that for me.

Cheers,
Paul



--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/KFVKhO7lYdw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Paul Wolstenholme
CBC Music - System Administrator
CBC  Vancouver
604.662.6632
Reply all
Reply to author
Forward
0 new messages