problem with local_action and/or connection=local

Ansible version: 1.2 (one hour ago)

In ansible.cfg
transport=ssh
remote_user=root

My hosts file:

[lh]

127.0.0.1

My playbook:


  • hosts: lh

sudo: yes

tasks:

  • name: action echo cat

action: shell echo pwd

sudo: no

  • name: local_action echo cat

local_action: shell echo pwd

In ansible version 0.9 this is working (just tested it now), but from version 1.0 and up I git this output (see below for version 0.9 output):

$ ansible-playbook -vvv -i hosts main.yml

PLAY [lh] *********************

GATHERING FACTS *********************
<127.0.0.1> ESTABLISH CONNECTION FOR USER: root
<127.0.0.1> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, u’User=root’, ‘127.0.0.1’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-1370612111.97-208758030915962 && echo $HOME/.ansible/tmp/ansible-1370612111.97-208758030915962’”]
<127.0.0.1> REMOTE_MODULE setup
<127.0.0.1> PUT /tmp/tmp9gMKCJ TO /root/.ansible/tmp/ansible-1370612111.97-208758030915962/setup
<127.0.0.1> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, u’User=root’, ‘127.0.0.1’, u’/bin/sh -c 'sudo -k && sudo -H -S -p “[sudo via ansible, key=oxdyeugepbnkmhdeqvitdlovehtgdtlk] password: " -u root /bin/sh -c '”'“'/usr/bin/python /root/.ansible/tmp/ansible-1370612111.97-208758030915962/setup; rm -rf /root/.ansible/tmp/ansible-1370612111.97-208758030915962/ >/dev/null 2>&1'”'"''']
ok: [127.0.0.1]

TASK: [action echo cat] *********************
<127.0.0.1> ESTABLISH CONNECTION FOR USER: root
<127.0.0.1> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, u’User=root’, ‘127.0.0.1’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-1370612113.2-67083879678603 && echo $HOME/.ansible/tmp/ansible-1370612113.2-67083879678603’”]
<127.0.0.1> REMOTE_MODULE command echo pwd #USE_SHELL
<127.0.0.1> PUT /tmp/tmpRFbADf TO /root/.ansible/tmp/ansible-1370612113.2-67083879678603/command
<127.0.0.1> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, u’User=root’, ‘127.0.0.1’, u"/bin/sh -c ‘/usr/bin/python /root/.ansible/tmp/ansible-1370612113.2-67083879678603/command; rm -rf /root/.ansible/tmp/ansible-1370612113.2-67083879678603/ >/dev/null 2>&1’"]
changed: [127.0.0.1] => {“changed”: true, “cmd”: "echo pwd ", “delta”: “0:00:00.002072”, “end”: “2013-06-07 15:35:13.293487”, “rc”: 0, “start”: “2013-06-07 15:35:13.291415”, “stderr”: “”, “stdout”: “/root”}

TASK: [local_action echo cat] *********************
<127.0.0.1> EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-1370612113.33-211012426160008 && chmod a+rx $HOME/.ansible/tmp/ansible-1370612113.33-211012426160008 && echo $HOME/.ansible/tmp/ansible-1370612113.33-211012426160008’]
<127.0.0.1> REMOTE_MODULE command echo pwd #USE_SHELL
<127.0.0.1> PUT /tmp/tmpK7pZ7w TO /home/frans/.ansible/tmp/ansible-1370612113.33-211012426160008/command
<127.0.0.1> EXEC /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=pguxyoywxnpgyudsxxwocmmqzrwoxivc] password: " -u root /bin/sh -c '”’“‘/usr/bin/python /home/frans/.ansible/tmp/ansible-1370612113.33-211012426160008/command; rm -rf /home/frans/.ansible/tmp/ansible-1370612113.33-211012426160008/ >/dev/null 2>&1’”‘"’’
failed: [127.0.0.1] => {“failed”: true, “parsed”: false}

FATAL: all hosts have already failed – aborting

PLAY RECAP *********************
127.0.0.1 : ok=2 changed=1 unreachable=0 failed=1

The utput in ansible version 0.9 is:

ansible-playbook -vvv -i hosts main.yml

PLAY [lh] *********************

GATHERING FACTS *********************
<127.0.0.1> ESTABLISH CONNECTION FOR USER: root
<127.0.0.1> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, u’User=root’, ‘127.0.0.1’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-1370612945.32-217398837952549 && echo $HOME/.ansible/tmp/ansible-1370612945.32-217398837952549’”]
<127.0.0.1> REMOTE_MODULE setup
<127.0.0.1> PUT /tmp/tmpij5ter TO /root/.ansible/tmp/ansible-1370612945.32-217398837952549/setup
<127.0.0.1> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, u’User=root’, ‘127.0.0.1’, u’/bin/sh -c 'sudo -k && sudo -p “[sudo via ansible, key=wgvrtasdgrevksimahiwfraztcbiaqbi] password: " -u root /bin/sh -c '”'“'/usr/bin/python /root/.ansible/tmp/ansible-1370612945.32-217398837952549/setup; rm -rf /root/.ansible/tmp/ansible-1370612945.32-217398837952549/ >/dev/null 2>&1'”'"''']
ok: [127.0.0.1]

TASK: [action echo cat] *********************
<127.0.0.1> ESTABLISH CONNECTION FOR USER: root
<127.0.0.1> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, u’User=root’, ‘127.0.0.1’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-1370612947.92-130200028444731 && echo $HOME/.ansible/tmp/ansible-1370612947.92-130200028444731’”]
<127.0.0.1> REMOTE_MODULE command echo pwd #USE_SHELL
<127.0.0.1> PUT /tmp/tmpmFrzxf TO /root/.ansible/tmp/ansible-1370612947.92-130200028444731/command
<127.0.0.1> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, u’User=root’, ‘127.0.0.1’, u"/bin/sh -c ‘/usr/bin/python /root/.ansible/tmp/ansible-1370612947.92-130200028444731/command; rm -rf /root/.ansible/tmp/ansible-1370612947.92-130200028444731/ >/dev/null 2>&1’"]
changed: [127.0.0.1] => {“changed”: true, “cmd”: "echo pwd ", “delta”: “0:00:00.001230”, “end”: “2013-06-07 15:49:08.012663”, “rc”: 0, “start”: “2013-06-07 15:49:08.011433”, “stderr”: “”, “stdout”: “/root”}

TASK: [local_action echo cat] *********************
<127.0.0.1> EXEC mkdir -p $HOME/.ansible/tmp/ansible-1370612948.06-212987873710907 && chmod a+rx $HOME/.ansible/tmp/ansible-1370612948.06-212987873710907 && echo $HOME/.ansible/tmp/ansible-1370612948.06-212987873710907
<127.0.0.1> REMOTE_MODULE command echo pwd #USE_SHELL
<127.0.0.1> PUT /tmp/tmpO9Uls6 TO /home/frans/.ansible/tmp/ansible-1370612948.06-212987873710907/command
<127.0.0.1> EXEC sudo -u root -s /usr/bin/python /home/frans/.ansible/tmp/ansible-1370612948.06-212987873710907/command; rm -rf /home/frans/.ansible/tmp/ansible-1370612948.06-212987873710907/ >/dev/null 2>&1
changed: [127.0.0.1] => {“changed”: true, “cmd”: "echo pwd ", “delta”: “0:00:00.001365”, “end”: “2013-06-07 15:49:08.116814”, “rc”: 0, “start”: “2013-06-07 15:49:08.115449”, “stderr”: “”, “stdout”: “/home/frans/modules/ansible-playbooks/testing”}

PLAY RECAP *********************
127.0.0.1 : ok=3 changed=2 unreachable=0 failed=0

Thousands of folks are using local mode and haven’t reported any problems in 1.0 or 1.1 either (and most of them are running 1.2 pre-release now), so I am a bit curious about what you can share that is unique about your environment.

What sort of machine are you running Ansible from?

I am on Ubuntu 13.04. Will give more details tomorrow.

I’m running on 13.04 and I took your your playbook and a checkout of 1.2 (07a1365c5566). I’ll paste the play below. Everything seems to be working fine. My extra arguments are to override my configuration file which sets things like the user up.

Thanks Patrick for testing.

My missing argument in my test was: -K

I jumped from version 0.9 to 1.2, and apparently in 0.9 the script could run without the sudo password.

Problem solved
– Frans

Thanks Patrick for testing.

My missing argument in my test was: -K

I jumped from version 0.9 to 1.2, and apparently in 0.9 the script could
run without the sudo password.

Problem solved
-- Frans

Glad to have helped!

Hmm, that would a bit strange if that were true in 0.9, as the first implied task is “setup”, and that would run with the play settings.

Anyway, glad you have it figured out!

I think it is because of my setting remote_user=root in ansible.cfg (and i configured passwordless ssh root@localhost), in ansible 0.9 the local task was executed under the root user?

Now the local_action is executed under the local user that started the ansible-playbook and tries to sudo into root.

– Frans

Actually now that I think about it, Ansible 0.9 used to assume local connections for localhost, which is probably what it was.

If you still want that, an explicit “connection: local” will work for you.