# expect "Press enter to continue"

**URL:** <https://forum.ansible.com/t/expect-press-enter-to-continue/26033>\
**Category:** Ansible Project\
**Created:** [November 15, 2017, 2:07pm UTC](https://forum.ansible.com/t/expect-press-enter-to-continue/26033 "2017-11-15T14:07:58Z")\
**Posts on this page:** 8\
**Page:** 2

<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:** [November 17, 2017, 5:03pm UTC](https://forum.ansible.com/t/expect-press-enter-to-continue/26033/21 "2017-11-17T17:03:16Z")

</div>

> Yes kai it was the problem!
> 
> Now i am sure the number of exit is correct and the configuration go fine,  
> at the end now i get this message, even if the configuration is done i get  
> such an error how can i avoid it? I mean now this error it is not an error,  
> after i finished the configuration i exited the CLI and that's all.

\<snip /\>

> \* "msg": "non-zero return code",\*  
> \* "rc": 1,\*

The telnet command is returning return code 1, and Ansible takes that as a failure.

\<snip /\>

> \* "Global configuration mode",\*  
> \* "idg(config)# web-mgmt",\*  
> \* "Modify Web Management Service configuration",\*  
> \* "",\*  
> \* "idg(config web-mgmt)# admin-state enabled",\*  
> \* "idg(config web-mgmt)# local-address 127.0.0.1 9090",\*  
> \* "idg(config web-mgmt)# exit",\*  
> \* "",\*  
> \* "% The appliance is in failsafe console mode. Only the default  
> domain and a serial console interface are active. In this failsafe mode the  
> appliance cannot accept client requests. Contact IBM Support.",\*  
> \* "",\*  
> \* "idg(config)# write memory",\*  
> \* "",\*  
> \* "% Saving configuration failed - disabled.",\*  
> \* "",\*  
> \* "idg(config)# exit",\*  
> \* "",\*  
> \* "% The appliance is in failsafe console mode. Only the default  
> domain and a serial console interface are active. In this failsafe mode the  
> appliance cannot accept client requests. Contact IBM Support.",\*  
> \* "",\*  
> \* "idg# exit",\*  
> \* "Goodbye.",\*  
> \* "Connection closed by foreign host."\*  
> \* ]\*  
> \*}\*

This looks good but sometime some HW return an error anyway.  
Fortunately you have options to handle this[1].

One is to set

&nbsp;&nbsp;ignore\_errors: true

on the task, personally I don't like this one, since the output still looks like something went wrong.  
The other alternative is adding

&nbsp;&nbsp;fail\_when: false

or

&nbsp;&nbsp;register: result  
&nbsp;&nbsp;failed\_when: result.rc \> 1

to the task.

[1] [https://docs.ansible.com/ansible/latest/playbooks\_error\_handling.html](https://docs.ansible.com/ansible/latest/playbooks_error_handling.html)

---

<div class="post-metadata">

**Author:** ![ayyappan\_ramanan](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ayyappan\_ramanan](https://forum.ansible.com/u/ayyappan_ramanan)\
**Post date:** [November 17, 2017, 9:47pm UTC](https://forum.ansible.com/t/expect-press-enter-to-continue/26033/22 "2017-11-17T21:47:47Z")

</div>

Hi Stefano,

I am an Ansible newb. I have a similar problem as yours. I was looking for solutions to send break sequence to the console (Ctrl+]).

I am unsure if this helps, but in some google groups, I remember seeing EXPECT module being used to interact with such CLIs. Just in case if you did not try this before. Secondly, just a thought, could ‘\n’ solve your problem sending Carriage Return/Enter to CLI.

Glad if this helps,  
AR

---

<div class="post-metadata">

**Author:** ![stefano.bianchi](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@stefano.bianchi](https://forum.ansible.com/u/stefano.bianchi)\
**Post date:** [November 20, 2017, 9:17am UTC](https://forum.ansible.com/t/expect-press-enter-to-continue/26033/23 "2017-11-20T09:17:56Z")

</div>

Hi ayyappan ramanan

I finally figured out my issue, now i am able to configure the CLI correctly using expect module as explained by Kai.

Once i fixed minor issues, i will post the whole code so that can be helpful to everyone need this kind of configuration.

---

<div class="post-metadata">

**Author:** ![stefano.bianchi](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@stefano.bianchi](https://forum.ansible.com/u/stefano.bianchi)\
**Post date:** [November 20, 2017, 10:03am UTC](https://forum.ansible.com/t/expect-press-enter-to-continue/26033/24 "2017-11-20T10:03:32Z")

</div>

Here the code to make the CLI configuration:

**- name: Launch the CLI first time**  
**expect:**  
**command: telnet 0 2200**  
**responses:**  
**login: “user”**  
**Password: “passwd”**  
**Press any key to continue.: “”**  
**Enable Secure Backup mode.\*: “n”**  
**Enable Common Criteria Compatibility mode.\*: “n”**  
**Please enter new password._: “new\_password!”_**  
 _ **Please re-enter new password to confirm.** _ **: “new\_password!”**  
**idg#:**  
**- configure terminal**  
**- exit**  
**idg(config)#:**  
**- web-mgmt**  
**- write memory**  
**- “exit”**  
**idg(config web-mgmt)#:**  
**- “admin-state enabled”**  
**- “local-address ”**  
**- “exit”**  
**register: result**  
**failed\_when: result.rc \> 1**  
**tags:**  
**- cli**  
this code perform these actions:

1)Access the cli with telnet 0 2200  
2)insert default username and password  
3)Press enter  
4)Answer No to a couple of questions  
5)add new password and confirm it again  
6) then start with configuration:

> - configure terminal
> - web-mgmt
> - admin-state enabled
> - local-address host port
> - exit
> - write memory
> - exit

A tag “cli” is added in case to run only the last step, indeed this is the last step of a larger playbook

Hoping to help someone.

Regards

---

<div class="post-metadata">

**Author:** ![stefano.bianchi](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@stefano.bianchi](https://forum.ansible.com/u/stefano.bianchi)\
**Post date:** [November 20, 2017, 11:50am UTC](https://forum.ansible.com/t/expect-press-enter-to-continue/26033/25 "2017-11-20T11:50:51Z")

</div>

Here the code to make the CLI configuration:

**- name: Launch the CLI first time**  
**expect:**  
**command: telnet 0 2200**  
**responses:**  
**login: “user”**  
**Password: “passwd”**  
**Press any key to continue.: “”**  
**Enable Secure Backup mode.\*: “n”**  
**Enable Common Criteria Compatibility mode.\*: “n”**  
**Please enter new password._: “new\_password!”_**  
 _ **Please re-enter new password to confirm.** _ **: “new\_password!”**  
**idg#:**  
**- configure terminal**  
**- exit**  
**idg(config)#:**  
**- web-mgmt**  
**- write memory**  
**- “exit”**  
**idg(config web-mgmt)#:**  
**- “admin-state enabled”**  
**- “local-address ”**  
**- “exit”**  
**register: result**  
**failed\_when: result.rc \> 1**  
**tags:**  
**- cli**  
this code perform these actions:

1)Access the cli with telnet 0 2200  
2)insert default username and password  
3)Press enter  
4)Answer No to a couple of questions  
5)add new password and confirm it again  
6) then start with configuration:

> - configure terminal
> - web-mgmt
> - admin-state enabled
> - local-address host port
> - exit
> - write memory
> - exit

A tag “cli” is added in case to run only the last step, indeed this is the last step of a larger playbook

Hoping to help someone.

Regards

---

<div class="post-metadata">

**Author:** ![ayyappan\_ramanan](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ayyappan\_ramanan](https://forum.ansible.com/u/ayyappan_ramanan)\
**Post date:** [December 21, 2017, 6:15am UTC](https://forum.ansible.com/t/expect-press-enter-to-continue/26033/26 "2017-12-21T06:15:40Z")

</div>

Thanks for the update Stefano. Much appreciated. I have been wanting try your script and respond, but did not get a chance.

How do you run this playbook without specifying hosts?

---

<div class="post-metadata">

**Author:** ![ritesh0313](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@ritesh0313](https://forum.ansible.com/u/ritesh0313)\
**Post date:** [July 8, 2020, 10:19am UTC](https://forum.ansible.com/t/expect-press-enter-to-continue/26033/27 "2020-07-08T10:19:21Z")

</div>

Hi Stefano,

Is it necessary to install Pexpect on remote machine as well?

Thanks & Regards,  
Ritesh Gupta.

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [July 8, 2020, 11:15am UTC](https://forum.ansible.com/t/expect-press-enter-to-continue/26033/28 "2020-07-08T11:15:46Z")

</div>

> Hi Stefano,
> 
> Is it necessary to install Pexpect on remote machine as well?
> 
> Thanks & Regards,  
> Ritesh Gupta.

Yes, see the module documentation: [https://docs.ansible.com/ansible/latest/modules/expect\_module.html](https://docs.ansible.com/ansible/latest/modules/expect_module.html)

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

[Previous page](https://forum.ansible.com/t/expect-press-enter-to-continue/26033.md?page=1)
