IOS upgrade on cisco c9200 switch to install mode with cisco.ios.ios_command

Hello,
I have issue with this task in my playbook:

  • name: Install and Reload Switch
    cisco.ios.ios_command:
    commands:
    - command: install add file flash:cat9k_lite_iosxe.17.09.06a.SPA.bin activate commit
    prompt: This operation requires a reload of the system. Do you want to proceed?
    answer: ‘y’
    register: inrel_output
    vars:
    ansible_command_timeout: 1450

but i can see in debug msg
“stdout_lines”: [
[
“install_add_activate_commit: START Thu Mar 13 10:31:19 met 2025”,
“install_add: Adding IMG”,
“— Starting initial file syncing —”,
“Copying flash:cat9k_lite_iosxe.17.09.06a.SPA.bin from Switch 1 to Switch 1 2”,
“Info: Finished copying to the selected Switch”,
“Finished initial file syncing”,
“”,
“— Starting Add —”,
“Performing Add on all members”,
" [1] Finished Add package(s) on Switch 1",
" [2] Finished Add package(s) on Switch 2",
“Checking status of Add on [1 2]”,
“Add: Passed on [1 2]”,
“Finished Add”,
“”,
“Image added. Version: 17.09.06a.0.12”,
“”,
“install_activate: Activating IMG”,
“Following packages shall be activated:”,
“/flash/cat9k_lite-rpbase.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-rpboot.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-srdriver.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-webui.17.09.06a.SPA.pkg”,
“Following packages shall be activated:”,
“/flash/cat9k_lite-rpbase.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-rpboot.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-srdriver.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-webui.17.09.06a.SPA.pkg”,
“”,
“This operation may require a reload of the system. Do you want to proceed? [y/n]No User Response, Request Timeout”
]
]
}
}

Hi @Lukas_Dermisek, welcome to the Ansible Forum!

I don’t have much firsthand experience using the Cisco IOS module but I have a couple of suggestions based on the documentation example:

  • The prompt wording looks different between what you have and the debug message
    Playbook: “This operation requires a reload of the system. Do you want to proceed?”
    Debug: “This operation may require a reload of the system. Do you want to proceed? [y/n]”
  • You will probably need to escape the square brackets in “[y/n]”
  • The prompt will probably need to be enclosed with single quotes
- name: Run commands that require answering a prompt
  cisco.ios.ios_command:
    commands:
      - command: "clear counters GigabitEthernet2"
        prompt: 'Clear "show interface" counters on this interface \[confirm\]'
        answer: "y"
      - command: "clear counters GigabitEthernet3"
        prompt: "[confirm]"
        answer: "\r"

cisco.ios.ios_command module – Module to run commands on remote devices. — Ansible Community Documentation

Again, that’s a first pass based on the documentation. If someone with more working knowledge of the IOS module has a different take on it, I’ll definitely differ to them.

Best regards,

Joe

Hello,
Thanks for check, i have change ansible task base on your comments, but unfortunately same result as before:
-playbook task:
- name: Install and Reload Switch
cisco.ios.ios_command:
commands:
- command: “install add file flash:cat9k_lite_iosxe.17.09.06a.SPA.bin activate commit”
prompt: ‘This operation may require a reload of the system. Do you want to proceed? [y/n]’
answer: “y”
register: inrel_output
vars:
ansible_command_timeout: 1450

-debug output:
],
“stdout_lines”: [
[
“install_add_activate_commit: START Thu Mar 13 15:43:47 met 2025”,
“install_add: Adding IMG”,
“— Starting initial file syncing —”,
“Copying flash:cat9k_lite_iosxe.17.09.06a.SPA.bin from Switch 1 to Switch 1 2”,
“Info: Finished copying to the selected Switch”,
“Finished initial file syncing”,
“”,
“— Starting Add —”,
“Performing Add on all members”,
" [1] Finished Add package(s) on Switch 1",
" [2] Finished Add package(s) on Switch 2",
“Checking status of Add on [1 2]”,
“Add: Passed on [1 2]”,
“Finished Add”,
“”,
“Image added. Version: 17.09.06a.0.12”,
“”,
“install_activate: Activating IMG”,
“Following packages shall be activated:”,
“/flash/cat9k_lite-rpbase.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-rpboot.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-srdriver.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-webui.17.09.06a.SPA.pkg”,
“Following packages shall be activated:”,
“/flash/cat9k_lite-rpbase.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-rpboot.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-srdriver.17.09.06a.SPA.pkg”,
“/flash/cat9k_lite-webui.17.09.06a.SPA.pkg”,
“”,
“This operation may require a reload of the system. Do you want to proceed? [y/n]No User Response, Request Timeout”
]
]
}
}

I have completely removed [y/n] from the prompt and task completed succesfully. Many thanks Joe

playbook:

  • name: Install and Reload Switch
    cisco.ios.ios_command:
    commands:
    - command: “install add file flash:cat9k_lite_iosxe.17.09.06a.SPA.bin activate commit”
    prompt: ‘This operation may require a reload of the system. Do you want to proceed?’
    answer: “y”
    register: inrel_output
    vars:
    ansible_command_timeout: 1450

and i can see it in debug:
“This operation may require a reload of the system. Do you want to proceed? [y/n]y”,
“”,

1 Like