Expect module in ansible

60 views
Skip to first unread message

SARANYA devotional R

unread,
Jul 28, 2017, 1:14:06 PM7/28/17
to Ansible Project, sarah saran tammar
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!

Kai Stian Olstad

unread,
Jul 28, 2017, 3:14:28 PM7/28/17
to ansible...@googlegroups.com
On 28. juli 2017 19:14, SARANYA devotional R wrote:
> Expect module is not taking the password!

It does.
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.


--
Kai Stian Olstad

SARANYA devotional R

unread,
Jul 28, 2017, 4:49:47 PM7/28/17
to Ansible Project, ansible-pr...@olstad.com
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?

Kai Stian Olstad

unread,
Jul 28, 2017, 5:00:36 PM7/28/17
to ansible...@googlegroups.com
On 28. juli 2017 22:49, SARANYA devotional R wrote:
> 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.

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


--
Kai Stian Olstad

SARANYA devotional R

unread,
Jul 31, 2017, 2:02:53 PM7/31/17
to Ansible Project, ansible-pr...@olstad.com
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"
     OVM>:
      - list Repository
Reply all
Reply to author
Forward
0 new messages