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
`