"sudo: a password is required" error with "local_action: file path={{ fetch_directory }} state=directory"

Hi,

I have this error:

TASK [ceph-mon : create a local fetch directory if it does not exist] ********** task path: /Users/stephane/projets/tech-angels/test_ceph/vagrant/roles/ceph-mon/tasks/docker/create_configs.yml:2 Using module file /usr/local/lib/python2.7/site-packages/ansible/modules/core/files/file.py <localhost> ESTABLISH LOCAL CONNECTION FOR USER: stephane <localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p " echo $HOME/.ansible/tmp/ansible-tmp-1481019912.14-221559219655965 " && echo ansible-tmp-1481019912.14-221559219655965=" echo $HOME/.ansible/tmp/ansible-tmp-1481019912.14-221559219655965 " ) && sleep 0' <localhost> PUT /var/folders/7v/bs1393w960b4_g1_2b5h9sf00000gn/T/tmpSVsFnm TO /Users/stephane/.ansible/tmp/ansible-tmp-1481019912.14-221559219655965/file.py <localhost> EXEC /bin/sh -c 'chmod u+x /Users/stephane/.ansible/tmp/ansible-tmp-1481019912.14-221559219655965/ /Users/stephane/.ansible/tmp/ansible-tmp-1481019912.14-221559219655965/file.py && sleep 0' <localhost> EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-drwxnaweihqdaahqciaxhgilzausrdhj; /usr/local/opt/python/bin/python2.7 /Users/stephane/.ansible/tmp/ansible-tmp-1481019912.14-221559219655965/file.py; rm -rf "/Users/stephane/.ansible/tmp/ansible-tmp-1481019912.14-221559219655965/" > /dev/null 2>&1'"'"' && sleep 0' fatal: [ceph-test-1 -> localhost]: FAILED! => { "changed": false, "failed": true, "invocation": { "module_name": "file" }, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE" }

With this code:

`

  • name: create a local fetch directory if it does not exist
    local_action: file path={{ fetch_directory }} state=directory
    changed_when: false
    become: false
    run_once: true
    when: cephx or generate_fsid

`

Original source code is here: https://github.com/ceph/ceph-ansible/blob/master/roles/ceph-mon/tasks/docker/create_configs.yml#L2

Question: why if I have *become: false* file action use sudo ?

Best regards,
Stéphane

If I use:

`
become_user: stephane

`

It is working!

How can I configure Ansible to use always my current user when it execute local_action ?

More information about this subject: Bug Report: local_action execute command with sudo -u root instead my current user