Answers: <p>I figured out the issue. The "Question:" parameter needs to be omitted:<br>
      ---<br>
      - hosts: localhost<br>
        connection: local<br>
        gather_facts: false  </p>
  
  <pre><code>  tasks:
      - name: Expect Attempt
        expect:
          echo: yes
          command: telnet 10.233.82.7 2033
          responses:
            Connected to port 33. :  "echo"
            login: "admin"
            Password: "password"
  </code></pre>
  
Answers: CC BY-SA 3.0
Answers: 2018-03-15T14:12:35.963Z
Answers: 2018-03-15T14:20:24.493Z
Answers: 2018-03-15T14:20:24.493Z
Answers: wabbajack001
Body: <p>I would like to use the expect module in an ansible playbook to telnet through a termserver to reach a NetApp filer. I tried the telnet module, but using the port argument after the ip address doesn't seem to work.
  Manually I would type the following:</p>
  
  <pre><code>[sansible@scspr0415857001 ansible]$ telnet 10.233.82.7 2033  
  Trying 10.233.82.7...  
  Connected to 10.233.82.7.  
  Escape character is '^]'.  
  Connected to port 33.  
  
  login: admin  
  Password:  
  
  rtpsb-f6280-02a-1::&gt; 
  </code></pre>
  
  <p>~~~~~~~~~~~~~~~~~~~</p>
  
  <p>I think my issue is that the playbook is getting caught up on simulating a return keystroke after "Connected to port 33."  </p>
  
  <p>I've also tried using echo -ne '\n'  </p>
  
  <p>Playbook:</p>
  
  <pre><code>---
  - 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" 
  </code></pre>
  
  <p>The full traceback is:  </p>
  
  <pre><code>  File "/tmp/ansible_piMb3N/ansible_module_expect.py", line 190, in main  
      encoding='utf-8')  
  
  fatal: [localhost]: FAILED! =&gt; {  
      "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  
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>
  
Comments: CC BY-SA 3.0
Comments: 2018-03-09T15:51:36.093Z
Comments: The log indicates that it connected ok, to me it looks like the next pattern matching fails. Maybe try looking for the promt returned after the connection?
Comments: Dan Cornilescu
Comments: CC BY-SA 3.0
Comments: 2018-03-13T20:05:19.847Z
Comments: How do you edit to get rid of the stack exchange formatting?
Comments: wabbajack001
Comments: CC BY-SA 3.0
Comments: 2018-03-13T22:15:49.890Z
Comments: https://meta.stackexchange.com/editing-help
Comments: Dan Cornilescu
Tags: <ansible>
Title: Ansible Expect Module hung on attempting a simulated return keystroke
UserDisplayName: wabbajack001
ThreadText: # Ansible Expect Module hung on attempting a simulated return keystroke
  
  (Asked by: username_0 on 2018-03-08)
  
  I would like to use the expect module in an ansible playbook to telnet through a termserver to reach a NetApp filer. I tried the telnet module, but using the port argument after the ip address doesn't seem to work.
  Manually I would type the following:
  
  ```
  [sansible@scspr0415857001 ansible]$ telnet 10.233.82.7 2033  
  Trying 10.233.82.7...  
  Connected to 10.233.82.7.  
  Escape character is '^]'.  
  Connected to port 33.  
  
  login: admin  
  Password:  
  
  rtpsb-f6280-02a-1::> 
  
  ```
  
  ~~~~~~~~~~~~~~~~~~~
  
  I think my issue is that the playbook is getting caught up on simulating a return keystroke after "Connected to port 33."
  
  I've also tried using echo -ne '\n'
  
  Playbook:
  
  ```
  ---
  - 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" 
  
  ```
  
  The full traceback is:
  
  ```
    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  
  
  ```
  
  Any help would be greatly appreciated!
  
  **Tags:** ansible
  
  > **Comments:**
  > **username_1**: The log indicates that it connected ok, to me it looks like the next pattern matching fails. Maybe try looking for the promt returned after the connection?  
  > **username_0**: How do you edit to get rid of the stack exchange formatting?  
  > **username_1**: https://meta.stackexchange.com/editing-help  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-03-15. Score: 1 | Accepted answer
  
  I figured out the issue. The "Question:" parameter needs to be omitted:  
  ---  
  - hosts: localhost  
  connection: local  
  gather\_facts: false
  
  ```
    tasks:
      - name: Expect Attempt
        expect:
          echo: yes
          command: telnet 10.233.82.7 2033
          responses:
            Connected to port 33. :  "echo"
            login: "admin"
            Password: "password"
  
  ```
  
  
  ---
  
  