# Expect module in ansible

**URL:** <https://forum.ansible.com/t/expect-module-in-ansible/25118>\
**Category:** Ansible Project\
**Created:** [July 28, 2017, 5:14pm UTC](https://forum.ansible.com/t/expect-module-in-ansible/25118 "2017-07-28T17:14:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SARANYA\_devotional\_R](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SARANYA\_devotional\_R](https://forum.ansible.com/u/SARANYA_devotional_R)\
**Post date:** [July 28, 2017, 5:14pm UTC](https://forum.ansible.com/t/expect-module-in-ansible/25118/1 "2017-07-28T17:14:06Z")

</div>

Expect module is not taking the password!

Task:

- expect:  
command: ssh -l admin localhost -p 10000  
responses:  
admin@localhost’s password: “xyz”

Error:

TASK [unpresentrepo : expect] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [10.100.100.187]: FAILED! =\> {“changed”: true, “cmd”: “ssh -l admin localhost -p 10000”, “delta”: “0:00:30.592311”, “end”: “2017-07-28 13:12:23.385812”, “failed”: true, “rc”: 255, “start”: “2017-07-28 13:11:52.793501”, “stdout”: "admin@localhost’s password: \r\nOVM\> ", “stdout\_lines”: ["admin@localhost’s password: ", "OVM\> "]}  
to retry, use: --limit @/home/sara.bckup.priv/main.retry

Please help!

---

<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:** [July 28, 2017, 7:14pm UTC](https://forum.ansible.com/t/expect-module-in-ansible/25118/2 "2017-07-28T19:14:11Z")

</div>

> Expect module is not taking the password!

It does.

> Task:  
> &nbsp;&nbsp;- expect:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: ssh -l admin localhost -p 10000  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;responses:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;admin@localhost's password: "xyz"
> 
> Error:
> 
> TASK [unpresentrepo : expect]  
> \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [10.100.100.187]: FAILED! =\> {"changed": true, "cmd": "ssh -l admin  
> localhost -p 10000", "delta": "0:00:30.592311", "end": "2017-07-28  
> 13:12:23.385812", "failed": true, "rc": 255, "start": "2017-07-28  
> 13:11:52.793501", "stdout": "admin@localhost's password: \r\nOVM\> ",  
> "stdout\_lines": ["admin@localhost's password: ", "OVM\> "]}  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;to retry, use: --limit @/home/sara.bckup.priv/main.retry

If you look at stdout or stdout\_lines you'll see to lines.  
One is "admin@localhost's password: " and the second is "OVM\> "

So it has logged in and gotten a new prompt, OVM\>.  
Delta is over 30 second and default timeout for expect is 30 second. So expect has been waiting for 30 seconds for more input, but you have only provided one input and the task times out.

---

<div class="post-metadata">

**Author:** ![SARANYA\_devotional\_R](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SARANYA\_devotional\_R](https://forum.ansible.com/u/SARANYA_devotional_R)\
**Post date:** [July 28, 2017, 8:49pm UTC](https://forum.ansible.com/t/expect-module-in-ansible/25118/3 "2017-07-28T20:49:46Z")

</div>

Thanks Kai!

I am a new beginner to Ansible. if I want to execute series of a commands in OVM prompt like list repository etc, what should I do?

---

<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:** [July 28, 2017, 9:00pm UTC](https://forum.ansible.com/t/expect-module-in-ansible/25118/4 "2017-07-28T21:00:13Z")

</div>

> Thanks Kai!
> 
> I am a new beginner to Ansible. if I want to execute series of a commands  
> in OVM prompt like list repository etc, what should I do?

Expect takes a list on responses, the fist time it get the response it will give the first entry, on the second respense the second and so on.

I don't know what commands a OVM prompt take, but lets say you would like to run "show something", "list something" and "get something" in that order it would be like this.

&nbsp;&nbsp;&nbsp;- expect:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: ssh -l admin localhost -p 10000  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;responses:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;admin@localhost's password: "xyz"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\>:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- show something  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- list something  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- get something

---

<div class="post-metadata">

**Author:** ![SARANYA\_devotional\_R](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@SARANYA\_devotional\_R](https://forum.ansible.com/u/SARANYA_devotional_R)\
**Post date:** [July 31, 2017, 6:02pm UTC](https://forum.ansible.com/t/expect-module-in-ansible/25118/5 "2017-07-31T18:02:52Z")

</div>

Its not giving the output for list Repository command.

fatal: [10.100.100.187]: FAILED! =\> {  
“changed”: true,  
“cmd”: “ssh -l admin localhost -p 10000”,  
“delta”: “0:00:30.821117”,  
“end”: “2017-07-31 13:54:57.711477”,  
“failed”: true,  
“invocation”: {  
“module\_args”: {  
“chdir”: null,  
“command”: “ssh -l admin localhost -p 10000”,  
“creates”: null,  
“echo”: false,  
“removes”: null,  
“responses”: {  
“OVM\>”: [  
“list Repository”  
],  
“admin@localhost’s password”: “xyz”  
},  
“timeout”: 30  
}  
},  
“rc”: 255,  
“start”: “2017-07-31 13:54:26.890360”,  
“stdout”: “OVM\> list Repository”,  
“stdout\_lines”: [  
“OVM\> list Repository”  
]  
}  
to retry, use: --limit @/home/sara.bckup.priv/main.retry

task:

- expect:  
command: ssh -l admin localhost -p 10000  
responses:  
admin@localhost’s password: “xyz”

> :

- list Repository
