# wait\_for and local\_action comes back with an error about sudo

**URL:** <https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070>\
**Category:** Ansible Project\
**Created:** [November 7, 2012, 1:54pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070 "2012-11-07T13:54:46Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [November 7, 2012, 1:54pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/1 "2012-11-07T13:54:46Z")

</div>

Hi List,

I’m trying to reboot a server from a playlist and then have the playlist wait for the server to come back before continuing with it’s next action.

So this is the playbook part:

> * * *
> 
> - hosts: 10.137.0.145
> 
> user: mark
> 
> sudo: true
> 
> vars:
> 
> hostname: servername01
> 
> sid: ABC2
> 
> tasks:
> 
> - name: Make /etc/hostname/ correct
> 
> action: lineinfile dest=/etc/hostname backup=true state=present regexp=^ line=‘$hostname’
> 
> - name: Reboot
> 
> action: command /sbin/reboot
> 
> - name: Wait for it to come back
> 
> local\_action: wait\_for host=10.137.0.145 port=22 delay=5 timeout=300

And this is the error it gives me:

> sudo password:
> 
> PLAY [10.137.0.145] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> ok: [10.137.0.145]
> 
> TASK: [Make /etc/hostname/ correct] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> ok: [10.137.0.145] =\> {“changed”: false, “msg”: “”}
> 
> TASK: [Reboot] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> changed: [10.137.0.145] =\> {“changed”: true, “cmd”: [“/sbin/reboot”], “delta”: “0:00:00.069021”, “end”: “2012-11-07 14:51:07.350678”, “rc”: 0, “start”: “2012-11-07 14:51:07.281657”, “stderr”: “”, “stdout”: “”}
> 
> TASK: [Wait for it to come back] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> fatal: [10.137.0.145] =\> sudo with password is presently only supported on the ‘paramiko’ (SSH) and native ‘ssh’ connection types
> 
> FATAL: all hosts have already failed – aborting
> 
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> 10.137.0.145 : ok=3 changed=1 unreachable=1 failed=0

So I’m doing something wrong here. Any idea’s?

Thanks,  
Mark

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [November 7, 2012, 2:02pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/2 "2012-11-07T14:02:32Z")

</div>

You're not doing anything wrong, but the local connection plugin  
doesn't yet support sudo with a password:

[https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/connection\_plugins/local.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/connection_plugins/local.py)

Suggestion is to allow passwordless sudo or to patch the module.

--Michael

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [November 7, 2012, 3:09pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/3 "2012-11-07T15:09:19Z")

</div>

Ah that’s why… Makes sense.

Can I make the assumption that a lot of you are just running ansible from the root user?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [November 7, 2012, 3:16pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/4 "2012-11-07T15:16:04Z")

</div>

Nope.

local\_action is a corner case, and many of us \*do\* have sudo  
configured to not require a password, or are not using local\_action.

You may wish to do "delegate\_to: localhost" instead.

I think for a while we didn't assume localhost was "-c local" but it's  
a bit of a damned if we do, damned if we don't scenario -- you get  
equal questions either way. (why do I need to be able to SSH into  
myself, etc).

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [November 7, 2012, 3:21pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/5 "2012-11-07T15:21:12Z")

</div>

Not really,

I have encountered this issue also, I’m looking at how to solve this in a way that works for others and that makes sense to integrate into ansible.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [November 7, 2012, 3:21pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/6 "2012-11-07T15:21:58Z")

</div>

Don’t get me wrong, I still think ansible is a beautifull tool in mijn toolkit. The quirks are more or less obvious and are easily solvable all from the main “ansible” server.

NOPASSWD is on it’s way. 😉

Mark

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [November 7, 2012, 3:25pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/7 "2012-11-07T15:25:34Z")

</div>

@bcoca -- thanks -- I figure if you can get this figured out, we may  
be able to support the --ask-sudo-pass for -c ssh as well.

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [November 7, 2012, 3:33pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/8 "2012-11-07T15:33:50Z")

</div>

Michael DeHaan wrote:

> @bcoca -- thanks -- I figure if you can get this figured out, we may  
> be able to support the --ask-sudo-pass for -c ssh as well.

It is already supported. Regular passwords are what aren't.

Daniel

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [November 7, 2012, 3:35pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/9 "2012-11-07T15:35:15Z")

</div>

Mark Maas wrote:

> Hi List,
> 
> I'm trying to reboot a server from a playlist and then have the playlist  
> wait for the server to come back before continuing with it's next action.
> 
> So this is the playbook part:
> 
> ---  
> - hosts: 10.137.0.145  
> &nbsp;&nbsp;user: mark  
> &nbsp;&nbsp;sudo: true  
> &nbsp;&nbsp;vars:  
> &nbsp;&nbsp;&nbsp;hostname: servername01  
> &nbsp;&nbsp;&nbsp;sid: ABC2  
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;- name: Make /etc/hostname/ correct  
> &nbsp;&nbsp;&nbsp;&nbsp;action: lineinfile dest=/etc/hostname backup=true state=present  
> regexp=^ line='$hostname'  
> &nbsp;&nbsp;- name: Reboot  
> &nbsp;&nbsp;&nbsp;&nbsp;action: command /sbin/reboot  
> &nbsp;&nbsp;- name: Wait for it to come back  
> &nbsp;&nbsp;&nbsp;&nbsp;local\_action: wait\_for host=10.137.0.145 port=22 delay=5 timeout=300

What you want here is a  
&nbsp;&nbsp;&nbsp;&nbsp;sudo: False  
to disable sudo for this task.

Daniel

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [November 7, 2012, 3:47pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/10 "2012-11-07T15:47:56Z")

</div>

Not neccessarily, suppose you want to sudo.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [November 7, 2012, 8:03pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/11 "2012-11-07T20:03:43Z")

</div>

Indeed, the only thing that seems to work with wait\_for is to use NOPASSWD on ALL the servers which is a big no-no in my book.  
NOPASSWD on the ansible server is one thing, but on all of them…

Is there another way I can do this without resorting to that?

mmaas@pmgtansible:~/playbooks/binck$ cat ./test.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [November 7, 2012, 8:18pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/12 "2012-11-07T20:18:08Z")

</div>

Fix the local connection module to make it support taking the password.

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [November 7, 2012, 8:22pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/13 "2012-11-07T20:22:34Z")

</div>

Excellent, except you may not want my code 😉 Still learning simple lists and dictionaries. It’l be a while.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [November 7, 2012, 8:39pm UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/14 "2012-11-07T20:39:08Z")

</div>

temporary workaround:

delegate\_to: 127.0.0.2  
(versus local\_action)

will almost definitely make it not use the local connection

---

<div class="post-metadata">

**Author:** ![Mark\_Maas](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Mark\_Maas](https://forum.ansible.com/u/Mark_Maas)\
**Post date:** [November 8, 2012, 6:16am UTC](https://forum.ansible.com/t/wait-for-and-local-action-comes-back-with-an-error-about-sudo/12070/15 "2012-11-08T06:16:07Z")

</div>

Excellent! Thanks!
