handler with listed variables

Hello,

I’m having trouble to figure out the best way to use handler with listed variables. My setup is as follow:

vars:
omd_sites:

  • prod
  • stg
  • dev3

tasks:

  • name: Template groups.mk
    template:
    src: groups.mk.j2
    dest: “/opt/omd/sites/{{ item }}/etc/check_mk/conf.d/groups.mk”
    owner: “{{ item }}”
    group: "{{ item }}
    with_items: “{{ omd_sites }}”
    notify: cmk reload

handlers:
# option1

  • name: cmk reload
    command: su -c “cmk -O” -l “{{omd_sites}}”
    Error:
    FAILED! => {“changed”: true, “cmd”: [“su”, “-c”, “cmk -O”, “-l”, “[u’prod’, u’stg’, u’dev3’]”], “delta”: “0:00:00.002481”, “end”: “2017-07-05 13:11:30.514962”, “failed”: true, “rc”: 1, “start”: “2017-07-05 13:11:30.512481”, “stderr”: “su: user [u’prod’, u’stg’, u’dev3’] does not exist”, “stderr_lines”: [“su: user [u’prod’, u’stg’, u’dev3’] does not exist”], “stdout”: “”, “stdout_lines”: }

# option2

  • name: cmk reload
    command: su -c “cmk -O” -l “{{omd_sites}}”

Error:
FAILED! => {“changed”: true, “cmd”: [“su”, “-c”, “cmk -O”, “-l”, “[uprod,”, “ustg,”, “udev3]”], “delta”: “0:00:00.002500”, “end”: “2017-07-05 13:20:09.621223”, “failed”: true, “rc”: 1, “start”: “2017-07-05 13:20:09.618723”, “stderr”: “su: user [uprod, does not exist”, “stderr_lines”: [“su: user [uprod, does not exist”], “stdout”: “”, “stdout_lines”: }

# option3

  • name: cmk reload
    command: “cmk -O”
    become_user: “{{omd_sites}}”
    become_method: su
    become: true

Error:
FAILED! => {“changed”: false, “failed”: true, “module_stderr”: “Shared connection to hmlb1mon07 closed.\r\n”, “module_stdout”: “su: user [uprod, does not exist\r\n”, “msg”: “MODULE FAILURE”, “rc”: 1}

How can I run handler only for {{ omd_sites }} item that changed and this has to be done by the {{ omd_sites }} user (account name the same as {{ omd_sites }} item)

Regards

Raf