# play-book + template hangs up.

**URL:** <https://forum.ansible.com/t/play-book-template-hangs-up/11425>\
**Category:** Ansible Project\
**Created:** [April 19, 2012, 6:40am UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425 "2012-04-19T06:40:32Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodney\_Quillo](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@Rodney\_Quillo](https://forum.ansible.com/u/Rodney_Quillo)\
**Post date:** [April 19, 2012, 6:40am UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/1 "2012-04-19T06:40:32Z")

</div>

I'm running ansible with virtualenv.

$ yolk -l  
Jinja2 - 2.6 - active  
PyYAML - 3.10 - active  
Python - 2.6.6 - active development (/opt/local/  
Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-  
dynload)  
paramiko - 1.7.7.1 - active  
pip - 0.6.3 - active  
pycrypto - 2.5 - active  
setuptools - 0.6c12dev-r88846 - active  
wsgiref - 0.1.2 - active development (/opt/local/  
Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6)  
yolk - 0.4.3 - active

$ cat sample-template.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:** [April 19, 2012, 12:00pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/2 "2012-04-19T12:00:12Z")

</div>

> $ ansible all -m setup -u ubuntu
> 
> Now, host file has a single server running Ubuntu Oneiric.  
> [web-servers]  
> xx.xx.xx.xx
> 
> $ ansible-playbook sample-template.yml -T 30 --debug

If setup didn’t hang in your above test execution from /usr/bin/ansible, that is interesting. What happens if you do something like:

ansible -m template -a “template src=templates/foo.j2 dest=/etc/some\_random\_foo.conf” -D ?

-D will show the standard output of the module.

(You can also use -D with playbooks).

Since the regular CLI worked to execute setup it doesn’t look like it’s an issue with logging in or SSH.

Depending on the answer to that I should have some other things for you to try.

I should also add that templates work differently on the integration branch, but we’re working on those. I assume  
you are running off the master branch? If so, lots of people have been using those and I wouldn’t expect  
the hang.

Anyway, let me know. Thanks!

---

<div class="post-metadata">

**Author:** ![Rodney\_Quillo](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@Rodney\_Quillo](https://forum.ansible.com/u/Rodney_Quillo)\
**Post date:** [April 19, 2012, 2:15pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/3 "2012-04-19T14:15:19Z")

</div>

SSH Agent are running ok.

ansible)ubuntu@testbox:~/my-github/ansible/examples/playbooks$ ansible  
web-servers -m setup -u ubuntu  
192.168.2.140 | success \>\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"changed": false,  
&nbsp;&nbsp;&nbsp;&nbsp;"md5sum": "c226357c730f7b88bd8d3167b9b6f65e",  
&nbsp;&nbsp;&nbsp;&nbsp;"metadata": "/home/ubuntu/.ansible/setup",  
&nbsp;&nbsp;&nbsp;&nbsp;"written": "/home/ubuntu/.ansible/setup"  
}

(ansible)ubuntu@testbox:~/my-github/ansible/examples/playbooks$  
ansible 192.168.2.140 -m setup -u ubuntu  
192.168.2.140 | success \>\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"changed": false,  
&nbsp;&nbsp;&nbsp;&nbsp;"md5sum": "c226357c730f7b88bd8d3167b9b6f65e",  
&nbsp;&nbsp;&nbsp;&nbsp;"metadata": "/home/ubuntu/.ansible/setup",  
&nbsp;&nbsp;&nbsp;&nbsp;"written": "/home/ubuntu/.ansible/setup"  
}

(ansible)ubuntu@testbox:~/my-github/ansible/examples/playbooks$  
ansible 192.168.2.140 -m template -a "template src=templates/foo.j2  
dest=/etc/some\_random\_foo.conf" --debug  
192.168.2.140 | FAILED =\> FAILED: Authentication failed.  
(ansible)ubuntu@testbox:~/my-github/ansible/examples/playbooks$  
ansible web-servers -m template -a "template src=templates/foo.j2  
dest=/etc/some\_random\_foo.conf" --debug  
192.168.2.140 | FAILED =\> FAILED: Authentication failed.  
(ansible)ubuntu@testbox:~/my-github/ansible/examples/playbooks$

Seems will be starting to debug on this part.. btw, this is the master  
branch. I believe the integration branch will process templates  
locally.

---

<div class="post-metadata">

**Author:** ![Rodney\_Quillo](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@Rodney\_Quillo](https://forum.ansible.com/u/Rodney_Quillo)\
**Post date:** [April 19, 2012, 2:21pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/4 "2012-04-19T14:21:59Z")

</div>

Opps..seems the command using "ansible" only requires -u option and -  
s (sudo) for that file to be on /etc

ansible)ubuntu@testbox:~/my-github/ansible/examples/playbooks$ ansible  
192.168.2.140 -m template -a "template src=templates/foo.j2 dest=/etc/  
some\_random\_foo.conf -u ubuntu -s -D

And it hang's up there, let me check writing the template file to /tmp  
first.

---

<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:** [April 19, 2012, 2:24pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/5 "2012-04-19T14:24:22Z")

</div>

Looking at what you posted below, you are invoking setup with “-u ubuntu”, but not when running the template module.  
This would explain the problem as that would mean, without a “-u”, it is trying root.

For each play in a playbook, make sure you have the following:

user: ubuntu

And similarly, when you run templates from /usr/bin/ansible, don’t forget the -u either.

So I don’t think it’s hanging, it’s just an SSH timeout thing, most likely. -T 30 is 30 seconds, which is a long time.  
I would think it would fail immediately though versus waiting the 30, but… that could be the case.

Currently the “-D” is all about showing errors from the remote modules (for when modules crash), so it’s not going to give you any more information  
about authentication. (This will probably change in the future to also remind you about what user is it is connecting as,  
what ports it is trying to use, etc.)

–Michael

---

<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:** [April 19, 2012, 2:26pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/6 "2012-04-19T14:26:29Z")

</div>

> Opps…seems the command using “ansible” only requires -u option and -  
> s (sudo) for that file to be on /etc
> 
> ansible)ubuntu@testbox:~/my-github/ansible/examples/playbooks$ ansible  
> 192.168.2.140 -m template -a "template src=templates/foo.j2 dest=/etc/  
> some\_random\_foo.conf -u ubuntu -s -D
> 
> And it hang’s up there, let me check writing the template file to /tmp  
> first.

Beat me to it.

Yeah, I don’t think anything should be hanging.

It should basically fail with an appropriate error.

If you can figure out why it’s hanging (not sure of your Python experience) it would be nice to eliminate  
that glitch. I may also be able to investigate why this error path is acting weird for you later tonight, but  
offhand I haven’t seen it.

There’s nothing in the template module that has any retry logic, so it shouldn’t keep trying to do things.

---

<div class="post-metadata">

**Author:** ![Rodney\_Quillo](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@Rodney\_Quillo](https://forum.ansible.com/u/Rodney_Quillo)\
**Post date:** [April 19, 2012, 2:54pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/7 "2012-04-19T14:54:03Z")

</div>

While figuring out the error, I found one:  
[https://github.com/ansible/ansible/issues/178](https://github.com/ansible/ansible/issues/178)

Anyways, I think it's on the sudo or something on ssh.

(ansible)Cocoys-MacBook-Pro:playbooks cocoy$ ansible web-servers -m  
template -a "template src=templates/foo.j2 dest=/tmp/  
some\_random\_foo.conf" -u ubuntu  
192.168.2.140 | success \>\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"changed": false,  
&nbsp;&nbsp;&nbsp;&nbsp;"group": "ubuntu",  
&nbsp;&nbsp;&nbsp;&nbsp;"md5sum": "7f340d5391bbb20d631c9dbf11900f1b",  
&nbsp;&nbsp;&nbsp;&nbsp;"mode": 420,  
&nbsp;&nbsp;&nbsp;&nbsp;"path": "/tmp/some\_random\_foo.conf",  
&nbsp;&nbsp;&nbsp;&nbsp;"state": "file",  
&nbsp;&nbsp;&nbsp;&nbsp;"user": "ubuntu"  
}

(ansible)Cocoys-MacBook-Pro:playbooks cocoy$ ansible web-servers -m  
template -a "template src=templates/foo.j2 dest=/etc/  
some\_random\_foo.conf" -u ubuntu -s -D

.. now it hangs up here...

Any guys using "sudo" here? 🙂

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [April 19, 2012, 2:56pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/8 "2012-04-19T14:56:06Z")

</div>

I was having a hang on sudo also (on Ubuntu Oneiric). I did not have time to investigate, so I have not been using sudo for the moment.

---

<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:** [April 19, 2012, 2:59pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/9 "2012-04-19T14:59:26Z")

</div>

Yeah, this should use os.path.expanduser around that path.

Easy fix.

If your sudo requires a password and you do not supply one or it is wrong, that will happen. I have some notes that we need to fix things up in connection.py.  
If you get the password right (or it does not require one) it should not cause any problems.

(Sudo password is specified with --ask-sudo-pass)

I prefer and suggest using passwordless sudo where possible, but the password stuff seems to work fine. If you think you’re supplying the correct password  
and it’s still hanging, we may have some issues there where the app really needs to parse what is coming back from sudo so it can fail versus wait at the prompt.

---

<div class="post-metadata">

**Author:** ![Rodney\_Quillo](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@Rodney\_Quillo](https://forum.ansible.com/u/Rodney_Quillo)\
**Post date:** [April 19, 2012, 3:18pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/10 "2012-04-19T15:18:00Z")

</div>

> (Sudo password is specified with --ask-sudo-pass)

On Ubuntu, its setup as passwordless sudo.

---

<div class="post-metadata">

**Author:** ![Peter\_Sankauskas](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@Peter\_Sankauskas](https://forum.ansible.com/u/Peter_Sankauskas)\
**Post date:** [April 25, 2012, 9:20pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/11 "2012-04-25T21:20:04Z")

</div>

Hi,

I am experiencing the same thing. I just have localhost set up in my hosts file on Ubuntu, and when I try:

$ ansible local -a “/usr/bin/whoami” -u ubuntu -s -D

It hangs until I CTRL-C and get the following output:

^CTraceback (most recent call last):  
File “/home/ubuntu/ansible/bin/ansible”, line 170, in   
(runner, results) = cli.run(options, args)  
File “/home/ubuntu/ansible/bin/ansible”, line 102, in run  
return (runner, runner.run())  
File “/home/ubuntu/ansible/lib/ansible/runner.py”, line 715, in run  
results = self.\_parallel\_exec(hosts)  
File “/home/ubuntu/ansible/lib/ansible/runner.py”, line 673, in \_parallel\_exec  
while not result\_queue.empty():  
File “”, line 2, in empty  
File “/usr/lib/python2.7/multiprocessing/managers.py”, line 755, in \_callmethod  
self.\_connect()  
File “/usr/lib/python2.7/multiprocessing/managers.py”, line 742, in \_connect  
conn = self.\_Client(self.\_token.address, authkey=self.\_authkey)  
File “/usr/lib/python2.7/multiprocessing/connection.py”, line 169, in Client  
c = SocketClient(address)  
File “/usr/lib/python2.7/multiprocessing/connection.py”, line 289, in SocketClient  
s.connect(address)  
File “/usr/lib/python2.7/socket.py”, line 224, in meth  
return getattr(self.\_sock,name)(\*args)  
socket.error: [Errno 2] No such file or directory

I think ansible is just trying to do this isn’t it?

$ ssh [ubuntu@127.0.0.1](mailto:ubuntu@127.0.0.1) sudo whoami  
root

Which works fine without password entry.

Any ideas what would be causing the “-s” option to hang?

I really don’t want to allow SSHing as root, so this option needs to work before I can really get into using ansible.

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![Dave\_Coutu](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Dave\_Coutu](https://forum.ansible.com/u/Dave_Coutu)\
**Post date:** [April 25, 2012, 9:26pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/12 "2012-04-25T21:26:00Z")

</div>

Peter,

Does your sudo configure require a password for the user running sudo? If  
so, you need to specify the -K option which will prompt you for the sudo  
password. If not, let's continue to debug...

Dave

---

<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:** [April 25, 2012, 9:26pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/13 "2012-04-25T21:26:32Z")

</div>

Which branch are you using? There have been some recent attempts to upgrade sudo on devel.

Let me know which and try the other 🙂

---

<div class="post-metadata">

**Author:** ![Dave\_Coutu](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Dave\_Coutu](https://forum.ansible.com/u/Dave_Coutu)\
**Post date:** [April 25, 2012, 9:28pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/14 "2012-04-25T21:28:16Z")

</div>

I really need to read more closely... passwordless sudo, so not the  
problem... so excuse my question.... 🙂

I'm running the devel branch and sudo works fine for me with password...  
let me see if it breaks when I make it passwordless..

Dave

---

<div class="post-metadata">

**Author:** ![Peter\_Sankauskas](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@Peter\_Sankauskas](https://forum.ansible.com/u/Peter_Sankauskas)\
**Post date:** [April 25, 2012, 9:31pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/15 "2012-04-25T21:31:57Z")

</div>

Hi,

My sudoers file has the following:

ubuntu ALL=(ALL) NOPASSWD:ALL

so no password is needed.

Right now, I am using the master branch in Git. Doing this works without password, so I can confirm that.

$ ssh [ubuntu@127.0.0.1](mailto:ubuntu@127.0.0.1) sudo whoami  
root

Peter

---

<div class="post-metadata">

**Author:** ![Peter\_Sankauskas](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@Peter\_Sankauskas](https://forum.ansible.com/u/Peter_Sankauskas)\
**Post date:** [April 25, 2012, 10:27pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/16 "2012-04-25T22:27:55Z")

</div>

Ok, I switched from master to the devel branch and it works well. Will probably be in release 0.4.

Peter

---

<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:** [April 25, 2012, 10:29pm UTC](https://forum.ansible.com/t/play-book-template-hangs-up/11425/17 "2012-04-25T22:29:10Z")

</div>

I am learning on making 0.4 a shorter release cycle and pushing some features out to 0.5, as this is probably something people want.

That being said, it worked for me previously, but the sudo timing stuff was a rough cut. I can see where it could have problems.

Good deal!
