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

1,290 views
Skip to first unread message

Stéphane Klein

unread,
Dec 6, 2016, 5:33:56 AM12/6/16
to Ansible Project
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

Stéphane Klein

unread,
Dec 6, 2016, 8:36:36 AM12/6/16
to Ansible Project
Le mardi 6 décembre 2016 11:33:56 UTC+1, Stéphane Klein a écrit :
Question: why if I have `become: false` file action use sudo ?

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` ?

Stéphane Klein

unread,
Dec 7, 2016, 4:10:40 AM12/7/16
to Ansible Project
Reply all
Reply to author
Forward
0 new messages