# delegate\_to in combination with with\_items

**URL:** <https://forum.ansible.com/t/delegate-to-in-combination-with-with-items/28216>\
**Category:** Ansible Project\
**Created:** [July 31, 2018, 6:02pm UTC](https://forum.ansible.com/t/delegate-to-in-combination-with-with-items/28216 "2018-07-31T18:02:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [July 31, 2018, 6:02pm UTC](https://forum.ansible.com/t/delegate-to-in-combination-with-with-items/28216/1 "2018-07-31T18:02:10Z")

</div>

Why doesn’t the following work? Syntax issue? or bug?

`

- name: Backup home dir and nagios rights  
shell: “cd {{ dirpath }}; getfacl -R {{ dir }} \> {{ file }}.{{ ansible\_date\_time.date }}”  
with\_items:
- { dirpath: “/home/”, dir: “\*”, file: “home\_rights.txt” }
- { dirpath: “/tmp”, dir: “\*”, file: “tmp\_rights.txt” }
- { dirpath: “/usr/local/”, dir: “nagios”, file: “nagios\_rights.txt” }
- { dirpath: “/var/spool/mail/”, dir: “nagios”, file: “nagios\_mail\_rights.txt” }  
delegate\_to: “{{ ansible\_hostname }}”

`

Result:

`  
fatal: [ansible-oel6]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘dirpath’ is undefined\n\nThe error appears to have been in ‘/etc/ansible/playbooks/one-offs/clean\_up\_users.yml’: line 19, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Backup home dir and nagios rights\n ^ here\n”}

`

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [July 31, 2018, 6:02pm UTC](https://forum.ansible.com/t/delegate-to-in-combination-with-with-items/28216/2 "2018-07-31T18:02:50Z")

</div>

ansible version:  
ansible-2.6.1-1.el7.noarch

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 31, 2018, 6:10pm UTC](https://forum.ansible.com/t/delegate-to-in-combination-with-with-items/28216/3 "2018-07-31T18:10:33Z")

</div>

When using with\_items the variable is always item, so it's item.dirpath, item.dir and item.file.

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [July 31, 2018, 6:14pm UTC](https://forum.ansible.com/t/delegate-to-in-combination-with-with-items/28216/4 "2018-07-31T18:14:06Z")

</div>

Thanks Kai. I don’t know how I missed that one. I stared and stared at it but still missed it.
