expect "Press enter to continue"

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

  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

  fail_when: false

or

  register: result
  failed_when: result.rc > 1

to the task.

[1] https://docs.ansible.com/ansible/latest/playbooks_error_handling.html

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

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.

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

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

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?

Hi Stefano,

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

Thanks & Regards,
Ritesh Gupta.

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

Regards
        Racke