Multi prompt issue with cisco.ios.ios_command

163 views
Skip to first unread message

Bikram

unread,
Jan 25, 2024, 4:10:02 PM1/25/24
to ansible...@googlegroups.com
Hi Team,

I am trying to upgrade a cat9300 switch from version 16.06.06 to 17.09.04a. The switch is in bundle mode and will convert it to install mode as well.

Here is my task:

- name: Install and activate new IOS image

  cisco.ios.ios_command:

      commands:

        - command: 'install add file flash: cat9k_iosxe.17.09.04a.SPA.bin   activate commit'

          prompt:

             - 'Please confirm you have changed boot config to flash:packages.conf \[y/n\]'

             - 'This operation requires a reload of the system. Do you want to proceed\? \[y/n\]'

          answer:

             - 'y'

             - 'y'

  register: install_image

  vars:

      ansible_command_timeout: 1400


Problem is dealing with multi prompt (with some delay between prompts). My task can catch the first prompt and answer accordingly but failed to catch the second prompt.


Here is the actual output when I upgrade the switch manually:

XX-9300#install add file flash:cat9k_iosxe.17.09.04a.SPA.bin activate commit
install_add_activate_commit: START Sat Jan 20 04:36:32 UTC 2024
install_add_activate_commit: Adding PACKAGE

 

This operation requires a reload of the system. Do you want to proceed? 
Please confirm you have changed boot config to flash:packages.conf [y/n]y

 

--- Starting initial file syncing ---
[1]: Copying flash:cat9k_iosxe.17.09.04a.SPA.bin from switch 1 to switch 2
Finished initial file syncing

--- Starting Add ---
--- cut off some text----
Finished Add

install_add_activate_commit: Activating PACKAGE
Following packages shall be activated:
/flash/cat9k-wlc.17.09.04a.SPA.pkg
---cut off some text--

This operation requires a reload of the system. Do you want to proceed? [y/n]y
--- Starting Activate ---
Performing Activate on all members
  [1] Activate package(s) on switch 1


Any help is much appreciated.


Thanks

Bikram

dbs34

unread,
Jan 26, 2024, 11:51:32 AM1/26/24
to Ansible Project

Hi Bikram, 

You could try splitting the tasks into two seperate tasks and adding a pause.  see below.

- name: Install new IOS image hosts: cisco_switches tasks: - name: Add IOS image ios_command: commands: - command: install add file flash:cat9k_iosxe.17.09.04a.SPA.bin activate commit prompt: - 'Please confirm you have changed boot config to flash:packages.conf [y/n]' answer: - y register: add_result - name: Confirm flash boot config pause: seconds: 15 when: add_result is succeeded - name: Activate IOS image ios_command: commands: - '' prompt: - 'This operation requires a reload of the system. Do you want to proceed? [y/n]' answer: - y when: add_result is succeeded

Bikram

unread,
Jan 26, 2024, 4:00:26 PM1/26/24
to ansible...@googlegroups.com
Hi Smith,

Thanks for your suggestions but unfortunately, it's a single command and we cannot split it.
I am planning to use the 'ansible.netcommon.cli_command' module instead which has an option to check all conditions and I'm going to test it soon.

I find this module more effective than the ios_command module

- name: Install and activate new IOS image

  ansible.netcommon.cli_command:

      command: 'install add file {{ fsystem }}:{{ image_9300.image_name }} activate commit'

      check_all: true

      prompt:

        - 'Please confirm you have changed boot config to flash:packages.conf \[y/n\]'

        - 'Do you want to proceed\? \[y/n\]'

      answer:

        - 'y'

        - 'y'

  vars:

      ansible_command_timeout: 14400


-Bikram


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/60d09529-517d-4e00-abb7-2b5e27031754n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages