using ansible with spawn is preventing the inventory process

86 views
Skip to first unread message

Oğuz Yarımtepe

unread,
Jun 21, 2017, 9:13:56 AM6/21/17
to Ansible Project
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.


Brian Coca

unread,
Jun 21, 2017, 9:46:11 AM6/21/17
to Ansible Project
Ansible has tty detection which controls it's prompt behaviour, that
might be affecting your playbook.


----------
Brian Coca

Oğuz Yarımtepe

unread,
Jun 21, 2017, 12:13:31 PM6/21/17
to ansible...@googlegroups.com
So what do you suggest? 

Any other method to enter password at a bash script?


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/4vt1Buz9u8A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CACVha7cV%3Dega4mxqECwPQwCd%2BFePwnsOREO_j%3DEum2brKOShgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Oğuz Yarımtepe
http://about.me/oguzy

Brian Coca

unread,
Jun 21, 2017, 1:23:41 PM6/21/17
to Ansible Project
You can set the ansible_ssh_pass variable, preferably in inventory.


----------
Brian Coca

Oğuz Yarımtepe

unread,
Jun 21, 2017, 1:32:45 PM6/21/17
to ansible...@googlegroups.com
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?



----------
Brian Coca

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/4vt1Buz9u8A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Brian Coca

unread,
Jun 21, 2017, 1:36:57 PM6/21/17
to Ansible Project
use a lookup?

--------
Brian Coca

Oğuz Yarımtepe

unread,
Jun 21, 2017, 6:21:24 PM6/21/17
to ansible...@googlegroups.com
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 
---
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?


use a lookup?

--------
Brian Coca

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/4vt1Buz9u8A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Madhu

unread,
Jun 21, 2017, 9:59:22 PM6/21/17
to ansible...@googlegroups.com
Hi,

   I think it's timing out because of the spawn. Use 'set timeout -1' before the spawn command. That should solve the issue.

Thanks,
Madhu 

Sent from my iPhone
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAKtWOTTdO3860t0wSCVjxHK5X0oFtME3ukwJSuuU8Syw9muO7w%40mail.gmail.com.

Oğuz Yarımtepe

unread,
Jun 22, 2017, 1:09:29 AM6/22/17
to ansible...@googlegroups.com
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.

To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.

To post to this group, send email to ansible-project@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/4vt1Buz9u8A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Madhu

unread,
Jun 22, 2017, 1:13:37 AM6/22/17
to ansible...@googlegroups.com
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.

Oğuz Yarımtepe

unread,
Jun 22, 2017, 1:36:50 AM6/22/17
to ansible...@googlegroups.com
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.


For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Jun 22, 2017, 2:23:10 AM6/22/17
to ansible...@googlegroups.com
On 22.06.2017 00:21, Oğuz Yarımtepe wrote:
> 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.

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages