Notify based on with_items variable

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

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.

Hi Michael,

Thanks for clarifying that for me.

Cheers,
Paul