# Expect Module Help

**URL:** <https://forum.ansible.com/t/expect-module-help/26966>\
**Category:** Ansible Project\
**Created:** [March 12, 2018, 1:29pm UTC](https://forum.ansible.com/t/expect-module-help/26966 "2018-03-12T13:29:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samuel\_Sutton](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@Samuel\_Sutton](https://forum.ansible.com/u/Samuel_Sutton)\
**Post date:** [March 12, 2018, 1:29pm UTC](https://forum.ansible.com/t/expect-module-help/26966/1 "2018-03-12T13:29:21Z")

</div>

Hello everyone,

I’m messing around with expect and I can’t seem to get a match to get the ping command to fire again a second time. I’m assuming that I’m making a very common matching mistake that is alluding me. Any help would be greatly appreciated!

---

<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:** [March 12, 2018, 4:18pm UTC](https://forum.ansible.com/t/expect-module-help/26966/2 "2018-03-12T16:18:36Z")

</div>

Expect is used on command and script that is interactive, ping is not interactive.

---

<div class="post-metadata">

**Author:** ![Samuel\_Sutton](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@Samuel\_Sutton](https://forum.ansible.com/u/Samuel_Sutton)\
**Post date:** [March 13, 2018, 8:05pm UTC](https://forum.ansible.com/t/expect-module-help/26966/3 "2018-03-13T20:05:41Z")

</div>

Hey Kai,

Thanks for the reply. Is the same thing happening with expect playbook that I made to try to telnet?

Playbook:

```auto
---
- hosts: localhost
  connection: local
  gather_facts: false

  tasks:  
    - name: Expect Attempt  
      expect:  
        echo: yes  
        command: telnet 10.233.82.7 2033  
        responses:  
          Question:  
            - Connected to port* "echo"  
            - login: "admin"  
            - Password: "password" 

```

```auto
File "/tmp/ansible_piMb3N/ansible_module_expect.py", line 190, in main  
    encoding='utf-8')  

fatal: [localhost]: FAILED! => {  
    "changed": true,  
    "cmd": "telnet 10.233.82.7 2033",  
    "delta": "0:00:30.122472",  
    "end": "2018-03-08 13:08:12.487220",  
    "invocation": {  
        "module_args": {  
            "chdir": null,  
            "command": "telnet 10.233.82.7 2033",  
            "creates": null,  
            "echo": true,  
            "removes": null,  
            "responses": {  
                "Question": [  
                    "Connected to port* \"echo\"",  
                    {  
                        "login": "admin"  
                    },  
                    {  
                        "Password": "password"  
                    }  
                ]  
            },  
            "timeout": 30  
        }  
    },  
    "msg": "non-zero return code",  
    "rc": 1,  
    "start": "2018-03-08 13:07:42.364748",  
    "stdout": "Trying 10.233.82.7...\r\r\nConnected to 10.233.82.7.\r\r\nEscape character is '^]'.\r\r\nConnected to port 33. ",  
    "stdout_lines": [  
        "Trying 10.233.82.7...",  
        "",  
        "Connected to 10.233.82.7.",  
        "",  
        "Escape character is '^]'.",  
        "",  
        "Connected to port 33. "  
    ]  
}  
        to retry, use: --limit @/home/sansible/ansible/expect-r1.retry  

PLAY RECAP *********************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1  

```

---

<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:** [March 13, 2018, 8:32pm UTC](https://forum.ansible.com/t/expect-module-help/26966/4 "2018-03-13T20:32:03Z")

</div>

> Hey Kai,
> 
> Thanks for the reply. Is the same thing happening with expect playbook that  
> I made to try to telnet?

No, telnet is interactive, the problem you have now is wrong syntax.

> ---  
> - hosts: localhost  
> &nbsp;&nbsp;connection: local  
> &nbsp;&nbsp;gather\_facts: false
> 
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;- name: Expect Attempt  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo: yes  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: telnet 10.233.82.7 2033  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;responses:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Question:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Connected to port\* "echo"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- login: "admin"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Password: "password"

Question is the text/prompt/question you are checking for, it's not a directive for the expect module.

&nbsp;&nbsp;&nbsp;&nbsp;- name: Expect Attempt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expect:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo: yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;command: telnet 10.233.82.7 2033  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;responses:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;login: "admin"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Password: "password"

When expect sees login in the output it will type admin and press ENTER and type password when it sees Password or password since the expect module is case insensitive by default.  
I don't understand what you tried to do with 'Connected to port\* "echo"'

You should also check out this tread for just a few days ago that address the same problem you are having now.  
[https://groups.google.com/forum/#!topic/ansible-project/Cq1NhB98vQA](https://groups.google.com/forum/#!topic/ansible-project/Cq1NhB98vQA)

---

<div class="post-metadata">

**Author:** ![Samuel\_Sutton](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@Samuel\_Sutton](https://forum.ansible.com/u/Samuel_Sutton)\
**Post date:** [March 15, 2018, 2:06pm UTC](https://forum.ansible.com/t/expect-module-help/26966/5 "2018-03-15T14:06:54Z")

</div>

Kai,

It seems that editing out the “question:” helped.

I still have to add [Connected to port 33. : “echo”] to my playbook though. If I omit that line, the playbook will time out.

[sansible@scspr0415857001 ansible]$ cat expect-r6.yaml
