cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
899
Views
0
Helpful
10
Replies

Unable to reload N7k switch using ansible after upgrade

swattik
Level 1
Level 1

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.

- 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

# Reload the Nexus

    - name: Reload the Nexus Switch
      nxos_command:
        commands:
          - reload
        prompt: "This command will reboot the system. (y/n)?  [n]"
       
 #       provider: {{ cli }}
       

 #   - nxos_command:
 #       commands:
 #         - reload
#          - command: y
 #       check_all: true
 #   - nxos_command:
 #       prompt: This command will reboot the system. (y/n)?
 #         - answer: y
           
       
         
    - name: Wait for 1500 seconds
      wait_for_connection:
        delay: 90
        timeout: 1000    
1 Accepted Solution

Accepted Solutions

swattik
Level 1
Level 1

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

View solution in original post

10 Replies 10

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

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

swattik
Level 1
Level 1

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
}

@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

 

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

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

 

@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 

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

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

@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

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

swattik
Level 1
Level 1

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

Awesome, congrats!

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Thank you so much for your continuous support. Much appreciated.