# using ansible with spawn is preventing the inventory process

**URL:** <https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784>\
**Category:** Ansible Project\
**Created:** [June 21, 2017, 1:13pm UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784 "2017-06-21T13:13:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oguz\_Yarimtepe](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@Oguz\_Yarimtepe](https://forum.ansible.com/u/Oguz_Yarimtepe)\
**Post date:** [June 21, 2017, 1:13pm UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/1 "2017-06-21T13:13:56Z")

</div>

Hi,

I am using ansible-playbook at a script and passing password to t. Below is how i used it:

run.sh

#!/bin/bash

…

/bin/expect \<\<- DONE  
spawn ansible-playbook -i $1 $2 -u $Username -k --become-user root --become-method sudo --become  
expect "SSH password: "  
send “$Password\r”  
expect eof  
DONE

$ bash run.sh test.txt test/playbook.yml

# cat cyberark.txt

[all]  
FOO01  
FOO02  
FOO03  
FOO04  
FOO05

# bash run.sh foo.txt test/playbook.yml

spawn ansible-playbook -i test.txt foo/playbook.yml -u testuser -k --become-user root --become-method sudo --become  
SSH password:

PLAY [Swap operations] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [FOO01]

TASK [swap\_ops : swapoff] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [FOO01]

TASK [swap\_ops : swapon] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [FOO01]

PLAY [Swap operations] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [FOO02]

TASK [swap\_ops : swapoff] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [FOO02]

TASK [swap\_ops : swapon] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [FOO02]

PLAY [Swap operations] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [FOO03]

TASK [swap\_ops : swapoff] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Any idea why the playbook is ended at the 3rd one? when i use a inventory with two hosts, everything is fine. When the number of hosts in inventory increases, ansible is ending at some hosts.

It may be because of spawn usage. Any solution will be appreciated.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 21, 2017, 1:46pm UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/2 "2017-06-21T13:46:04Z")

</div>

Ansible has tty detection which controls it's prompt behaviour, that  
might be affecting your playbook.

---

<div class="post-metadata">

**Author:** ![Oguz\_Yarimtepe](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@Oguz\_Yarimtepe](https://forum.ansible.com/u/Oguz_Yarimtepe)\
**Post date:** [June 21, 2017, 4:13pm UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/3 "2017-06-21T16:13:25Z")

</div>

So what do you suggest?

Any other method to enter password at a bash script?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 21, 2017, 5:23pm UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/4 "2017-06-21T17:23:25Z")

</div>

You can set the ansible\_ssh\_pass variable, preferably in inventory.

---

<div class="post-metadata">

**Author:** ![Oguz\_Yarimtepe](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@Oguz\_Yarimtepe](https://forum.ansible.com/u/Oguz_Yarimtepe)\
**Post date:** [June 21, 2017, 5:32pm UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/5 "2017-06-21T17:32:29Z")

</div>

The password is being gathered by a curl command so it is dynamic. Is there a way to set ssh\_pass variable dynamic? Like something to get from an environment variable?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 21, 2017, 5:36pm UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/6 "2017-06-21T17:36:43Z")

</div>

use a lookup?

---

<div class="post-metadata">

**Author:** ![Oguz\_Yarimtepe](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@Oguz\_Yarimtepe](https://forum.ansible.com/u/Oguz_Yarimtepe)\
**Post date:** [June 21, 2017, 10:21pm UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/7 "2017-06-21T22:21:17Z")

</div>

Great tip.

Here is my folder structure:

group\_vars/all

some\_playbook/playbook.yml

inventory\_file

$ ansible-playbook -i inventory\_file some\_playbook/playbook.yml --become-user root --become-method sudo --become

# cat group\_vars/all

---

<div class="post-metadata">

**Author:** ![Madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@Madhu](https://forum.ansible.com/u/Madhu)\
**Post date:** [June 22, 2017, 1:59am UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/8 "2017-06-22T01:59:05Z")

</div>

Hi,

---

<div class="post-metadata">

**Author:** ![Oguz\_Yarimtepe](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@Oguz\_Yarimtepe](https://forum.ansible.com/u/Oguz_Yarimtepe)\
**Post date:** [June 22, 2017, 5:09am UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/9 "2017-06-22T05:09:13Z")

</div>

The lookup method sounds more Ansible way. timeout -1 solved the issue by the way. But i would like to solve the lookup problem also.

---

<div class="post-metadata">

**Author:** ![Madhu](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@Madhu](https://forum.ansible.com/u/Madhu)\
**Post date:** [June 22, 2017, 5:13am UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/10 "2017-06-22T05:13:23Z")

</div>

There is a default time out value for expect. That’s why its timing out. To disable the timeout, we are setting as -1. I don’t think its ansible issue.

---

<div class="post-metadata">

**Author:** ![Oguz\_Yarimtepe](https://avatars.discourse-cdn.com/v4/letter/o/d07c76/32.png) [@Oguz\_Yarimtepe](https://forum.ansible.com/u/Oguz_Yarimtepe)\
**Post date:** [June 22, 2017, 5:36am UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/11 "2017-06-22T05:36:38Z")

</div>

Instead of using expect, setting the ansible\_ssh\_pass is another solution. Instead of running ansible-playbook inside a script, i can directly use it and it may get the ssh password from group\_vars variable. I couldn’t make it, thats what i am trying to do now.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 22, 2017, 6:22am UTC](https://forum.ansible.com/t/using-ansible-with-spawn-is-preventing-the-inventory-process/24784/12 "2017-06-22T06:22:53Z")

</div>

> Great tip.
> 
> Here is my folder structure:
> 
> group\_vars/all
> 
> some\_playbook/playbook.yml
> 
> inventory\_file
> 
> $ ansible-playbook -i inventory\_file some\_playbook/playbook.yml  
> --become-user root --become-method sudo --become

If you are logging in as root you don't need become to root.

> # cat group\_vars/all  
> ---  
> ansible\_ssh\_pass: "{{lookup('pipe', '/usr/local/bin/passwordrelease',  
> allow\_unsafe=True)}}"  
> ansible\_user: root  
> ansible\_connection: ssh
> 
> /usr/local/bin/passwordrelease is echoing the password
> 
> This didn't work. When i check with -vvvvv i can see it is trying to  
> connect via root but, i got authentication error.  
> Any idea?

If the password is correct this should work.  
So is the passwword correct?  
Make sure your script add a new line at the end.
