# problem with local\_action and/or connection=local

**URL:** <https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922>\
**Category:** Ansible Project\
**Created:** [June 7, 2013, 2:00pm UTC](https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922 "2013-06-07T14:00:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frans\_Kuipers](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Frans\_Kuipers](https://forum.ansible.com/u/Frans_Kuipers)\
**Post date:** [June 7, 2013, 2:00pm UTC](https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922/1 "2013-06-07T14:00:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 7, 2013, 2:07pm UTC](https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922/2 "2013-06-07T14:07:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Frans\_Kuipers](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Frans\_Kuipers](https://forum.ansible.com/u/Frans_Kuipers)\
**Post date:** [June 7, 2013, 4:22pm UTC](https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922/3 "2013-06-07T16:22:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Patrick\_Regan](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Patrick\_Regan](https://forum.ansible.com/u/Patrick_Regan)\
**Post date:** [June 7, 2013, 4:40pm UTC](https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922/4 "2013-06-07T16:40:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Frans\_Kuipers](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Frans\_Kuipers](https://forum.ansible.com/u/Frans_Kuipers)\
**Post date:** [June 8, 2013, 9:59am UTC](https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922/5 "2013-06-08T09:59:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Patrick\_Regan](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@Patrick\_Regan](https://forum.ansible.com/u/Patrick_Regan)\
**Post date:** [June 8, 2013, 11:43am UTC](https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922/6 "2013-06-08T11:43:40Z")

</div>

> 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!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 8, 2013, 5:54pm UTC](https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922/7 "2013-06-08T17:54:54Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Frans\_Kuipers](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Frans\_Kuipers](https://forum.ansible.com/u/Frans_Kuipers)\
**Post date:** [June 8, 2013, 8:18pm UTC](https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922/8 "2013-06-08T20:18:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 8, 2013, 11:43pm UTC](https://forum.ansible.com/t/problem-with-local-action-and-or-connection-local/12922/9 "2013-06-08T23:43:34Z")

</div>

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.
