07-12-2024 06:49 AM
Hello Experts,
I'm trying to reboot one of my n7k using ansible but unable to do it. Tried all the possibilities but no luck. Can any one here please help me out in this matter.
Solved! Go to Solution.
07-17-2024 03:07 AM
Finally, Issue got resolved, Hurrey... @bigevilbeard you can use below module to reboot any NXOS device.
---
- name: Save and Reload the N7k
hosts: n7k
gather_facts: no
tasks:
- name: Reload the Nexus Switch
nxos_reboot:
confirm: true
07-12-2024 06:57 AM
This looks good @swattik i made a couple of changes, firstly in Reload the nexus switch task, where I added the response: "y" parameter to the nxos_command module, so this tells ansible to respond with "y" when prompted to confirm the reload. I also removed the unnecessary provider and check_all parameters, as well as the duplicate nxos_command tasks too. Let me know how this goes, i do not have a devices to try this on atm.
Hope this helps.
- name: Save and Reload the N7k
hosts: n7k
gather_facts: no
tasks:
- name: Save the config and verify current Boot variable
nxos_command:
commands:
- copy running-config startup-config vdc-all
- show boot
register: new_boot
- debug: var=new_boot.stdout_lines
- name: Reload the Nexus Switch
nxos_command:
commands:
- reload
prompt: "This command will reboot the system. (y/n)? [n]"
response: "y"
- name: Wait for 1500 seconds
wait_for_connection:
delay: 90
timeout: 1000
07-12-2024 08:51 AM
Hi @bigevilbeard Thanks for your quick response. I've tried your play but unfortunately getting similar kind of response.
Play :
- name: Reload the Nexus Switch nxos_command: commands: - reload prompt: This command will reboot the system. (y/n)? [n] y response: "y"
Error:
{
"msg": "Unsupported parameters for (nxos_command) module: prompt, response Supported parameters include: auth_pass, authorize, commands, host, interval, match, password, port, provider, retries, ssh_keyfile, timeout, transport, use_ssl, username, validate_certs, wait_for",
"invocation": {
"module_args": {
"commands": [
"reload"
],
"prompt": "This command will reboot the system. (y/n)? [n] y",
"response": "y"
}
},
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"_ansible_no_log": false,
"changed": false
}
07-12-2024 09:12 AM
@swattik sorry thats my fault, prompt and response parameters are not supported by the nxos_command module, try this way with the expect parm, hopefully this is supported!
- name: Save and Reload the N7k
hosts: n7k
gather_facts: no
tasks:
- name: Save the config and verify current Boot variable
nxos_command:
commands:
- copy running-config startup-config vdc-all
- show boot
register: new_boot
- debug: var=new_boot.stdout_lines
- name: Reload the Nexus Switch
nxos_command:
commands:
- reload
expect:
- pattern: "This command will reboot the system. (y/n)"
response: y
- name: Wait for 1500 seconds
wait_for_connection:
delay: 90
timeout: 1000
07-15-2024 03:46 AM
Hello @bigevilbeard , tried the play you have shared above, but unfortunately getting same error, seems the module doesn't support by NXOS. Below the error msg.
fatal: [x,x,x,x]: FAILED! => changed=false
ansible_facts:
discovered_interpreter_python: /usr/bin/python
invocation:
module_args:
commands:
- reload
expect:
- pattern: This command will reboot the system. (y/n)
response: y
msg: 'Unsupported parameters for (nxos_command) module: expect Supported parameters include: auth_pass, authorize, commands, host, interval, match, password, port, provider, retries, ssh_keyfile, timeout, transport, use_ssl, username, validate_certs, wait_for'
PLAY RECAP **************************************************************************************************************************************************
x.x.x.1 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
07-15-2024 04:18 AM
@swattik surprised that is not supported, ok so.. looks like the main issue is that nxos_command module doesn't natively handle interactive prompts like the reload confirmation. This is a bit of change in approach, but wonder if this solves the issue? I have seen a few threads in the past with the prompts being a blocker for automation and it can be hard to handle these.
- name: Reload Nexus 7K Switches
hosts: n7k
gather_facts: no
tasks:
- name: Save the config and verify current Boot variable
nxos_command:
commands:
- copy running-config startup-config vdc-all
- show boot
register: new_boot
- name: Display Boot Variables (Optional)
debug:
msg: "{{ new_boot.stdout_lines }}"
- name: Reload the Nexus Switch
nxos_command:
commands:
- reload
- name: Confirm Reload (Workaround for Expect)
nxos_command:
commands:
- y # Send 'y' to confirm the reload
wait_for:
- result[0] contains "Proceed with reload"
- name: Wait for the Switch to Go Offline
wait_for:
host: "{{ inventory_hostname }}"
port: 22
state: absent
delay: 30
timeout: 600
- name: Wait for the Switch to Come Back Online
wait_for:
host: "{{ inventory_hostname }}"
port: 22
state: present
delay: 60
timeout: 1200
07-17-2024 02:39 AM
Hi @bigevilbeard , getting below error for the 2nd task of the play.
fatal: [10.108.7.211]: FAILED! => changed=false
invocation:
module_args:
auth_pass: null
authorize: null
commands:
- y
host: null
interval: 1
match: all
password: null
port: null
provider: null
retries: 10
ssh_keyfile: null
timeout: null
transport: null
use_ssl: null
username: null
validate_certs: null
wait_for:
- result[0] contains "Proceed with reload"
msg: unable to apply conditional to result
PLAY RECAP **************************************************************************************************************************************************
10.108.7.211 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
07-17-2024 03:09 AM
@swattik ok, good this is getting closer, this error appears to be that the wait_for condition is being applied within the nxos_command - see if splitting this into two tasks helps....
- name: Reload Nexus 7K Switches with Improved Confirmation Handling
hosts: n7k
gather_facts: no
tasks:
- name: Save Configuration and Check Boot Variables
nxos_command:
commands:
- copy running-config startup-config vdc-all
- show boot
register: new_boot
- name: Display Boot Variables (Optional - for debugging)
debug:
var: new_boot
- name: Initiate Switch Reload
nxos_command:
commands:
- reload
- name: Confirm Reload Prompt
nxos_command:
commands:
- y # Send 'y' to confirm the reload
- name: Wait for Reload Confirmation
nxos_command:
commands:
- show logging logfile | include reload
register: reload_log
until: reload_log.stdout.find("Proceed with reload") != -1
retries: 10
delay: 5
- name: Wait for Switch to Go Offline
wait_for:
host: "{{ inventory_hostname }}"
port: 22
state: absent
delay: 30
timeout: 600
- name: Wait for Switch to Come Back Online
wait_for:
host: "{{ inventory_hostname }}"
port: 22
state: present
delay: 60
timeout: 1200
07-17-2024 03:07 AM
Finally, Issue got resolved, Hurrey... @bigevilbeard you can use below module to reboot any NXOS device.
---
- name: Save and Reload the N7k
hosts: n7k
gather_facts: no
tasks:
- name: Reload the Nexus Switch
nxos_reboot:
confirm: true
07-17-2024 03:35 AM
Awesome, congrats!
07-17-2024 04:30 AM
Thank you so much for your continuous support. Much appreciated.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide