# bug with "become" and "delegate\_to" directives and loops with Ansible 2

**URL:** <https://forum.ansible.com/t/bug-with-become-and-delegate-to-directives-and-loops-with-ansible-2/20441>\
**Category:** Ansible Project\
**Created:** [February 3, 2016, 3:31pm UTC](https://forum.ansible.com/t/bug-with-become-and-delegate-to-directives-and-loops-with-ansible-2/20441 "2016-02-03T15:31:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabix](https://avatars.discourse-cdn.com/v4/letter/f/85f322/32.png) [@fabix](https://forum.ansible.com/u/fabix)\
**Post date:** [February 3, 2016, 3:31pm UTC](https://forum.ansible.com/t/bug-with-become-and-delegate-to-directives-and-loops-with-ansible-2/20441/1 "2016-02-03T15:31:44Z")

</div>

I’ve written this little playbook to show the problem:

`

- name: test become  
hosts: localhost  
serial: 1  
tasks:
- name: create test directories  
file: path=/tmp/test/{{ item }} state=directory  
with\_items:
- one
- two  
delegate\_to: localhost  
become: true

`

It’s not very realistic because the delegated host is the same as the target host but the problem is the same with any target hosts.

Make a /tmp/test directory with root’s permissions only.

If you run this playbook with a non-root user but who has sudo rights, it will fail on the second item (“two”). The “one” directory will be created correctly.

`  
PLAY [test become] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK [create test directories] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [localhost → localhost] =\> (item=one)  
failed: [localhost → localhost] =\> (item=two) =\> {“failed”: true, “item”: “two”, “msg”: “There was an issue creating /tmp/test/two as requested: ‘module’ object has no attribute ‘EEXISTS’”, “path”: “/tmp/test/two”, “state”: “absent”}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=1 changed=0 unreachable=0 failed=1

`

`  
$ ansible-playbook --version  
ansible-playbook 2.0.0.2  
config file = /etc/ansible/ansible.cfg  
configured module search path = Default w/o overrides

`

---

<div class="post-metadata">

**Author:** ![fabix](https://avatars.discourse-cdn.com/v4/letter/f/85f322/32.png) [@fabix](https://forum.ansible.com/u/fabix)\
**Post date:** [February 3, 2016, 4:44pm UTC](https://forum.ansible.com/t/bug-with-become-and-delegate-to-directives-and-loops-with-ansible-2/20441/2 "2016-02-03T16:44:36Z")

</div>

Hmm, with ansible-playbook 2.1.0, that works. So, the bug is already fixed. Sorry for the noise.
