# handler with listed variables

**URL:** <https://forum.ansible.com/t/handler-with-listed-variables/24899>\
**Category:** Ansible Project\
**Created:** [July 5, 2017, 12:29pm UTC](https://forum.ansible.com/t/handler-with-listed-variables/24899 "2017-07-05T12:29:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trg.achilles](https://avatars.discourse-cdn.com/v4/letter/t/f4b2a3/32.png) [@trg.achilles](https://forum.ansible.com/u/trg.achilles)\
**Post date:** [July 5, 2017, 12:29pm UTC](https://forum.ansible.com/t/handler-with-listed-variables/24899/1 "2017-07-05T12:29:57Z")

</div>

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
