Developer

 View Only
last person joined: yesterday 

Expand all | Collapse all

Ansible Reboot Playbook

This thread has been viewed 55 times
  • 1.  Ansible Reboot Playbook

    Posted Nov 29, 2022 08:18 PM
    Hi there,  I am wondering if there is other playbook that could reboot an Aruba switch and wait for it to be alive or any one that could advise what did I miss on this playbook so that it will wait for the switch to be up and running. The second task did not execute at all after reboot task. Hope someone could share their experience on this.

    ## Reboot Switch

    ---

    - hosts: aoscx_6300

      roles:

        - role: arubanetworks.aoscx_role

      gather_facts: false

      vars:

        ansible_connection: network_cli

        ansible_network_os: aoscx

        ansible_python_interpreter: /usr/bin/python3

        ansible_command_timeout: 240

      tasks:

        - name: reboot device

          aoscx_command:

            commands:

              - command: 'boot system'

                prompt:

                  - '.*\(y\/n\)\?.*'

                answer:

                  -  y

        - name: Execute show version command

          aoscx_command:

           commands: ['show version']

          register: show_version_output

        - name: Output registered variable

          debug:

            var: show_version_output



    Thank you.


  • 2.  RE: Ansible Reboot Playbook

    Posted Nov 30, 2022 03:27 AM
    I have tried a lot of different things, but the only thing that works well is to have Ansible wait a while before continuing.
       - name: Wait for 10 minutes for switch to boot
          wait_for:
            timeout: 600
          delegate_to: localhost

    If anyone has a better solution, I am very interested as well.




  • 3.  RE: Ansible Reboot Playbook

    Posted Nov 30, 2022 03:32 AM
    In regards to your reboot command, you can also use firmware boot module instead of using the command module:
        - name: Boot to {{ boot_partition }}
          aoscx_boot_firmware:
            partition_name: '{{ boot_partition }}'
    
    or without variable:
    - name: Boot to primary
      aoscx_boot_firmware:
        partition_name: primary
    - name: Boot to secondary
      aoscx_boot_firmware:
        partition_name: secondary​



  • 4.  RE: Ansible Reboot Playbook

    EMPLOYEE
    Posted Dec 01, 2022 11:55 AM
    Hi @sudovim ! @jonlar is correct and we have an example of that workflow on our aoscx-ansible-workflows repository! Here's a snippet of the check_firmware_then_upgrade.yml playbook that does just that:

    - name: Boot the switch with the new image uploaded to primary partition.
      aoscx_boot_firmware:
    	partition_name: 'primary'
    - name: Wait for the switch to come online after FW upgrade and reboot.
      wait_for:
    	host: "{{ ansible_host }}"
    	port: 22
    	sleep: 10
    	timeout: 900​


  • 5.  RE: Ansible Reboot Playbook

    Posted Dec 02, 2022 04:05 AM
    Thanks for the reply :) I did try the following the other day on a 6200 stack, but it completed immediately. I will test with port 22 instead.
        - name: Wait for the switch to come online after reboot.
          ansible.builtin.wait_for:
            host: "{{ ansible_host }}"
            port: 443
            sleep: 30
            timeout: 600​



  • 6.  RE: Ansible Reboot Playbook

    EMPLOYEE
    Posted Dec 02, 2022 02:10 PM
    When working with a stack you'll want to use the "show vsf" command to check the members of the stack instead of the connection of the IP address. You should still validate the IP is reachable but then use SSH commands to validate all the members are up. Here's an example in our AOS-CX Ansible Workflows repo:
    - name: Wait for Standby to join stack by entering Show vsf
      aoscx_command:
    	commands:
    	  - 'show vsf'
    	wait_for:
    	  - result[0] contains "Standby"
    	  #- result[0] contains "Member"
    	match: all
    	retries: 20
    	interval: 5



  • 7.  RE: Ansible Reboot Playbook

    Posted Dec 02, 2022 09:23 PM
    Hi KS9,

    So are you saying that I should use the boot partition module to reboot the switch at the same time wait for the switch to be alive even if I don't really intend to change the boot partition? And there is no other way to achieve that except using @jonlar method. Correct me if I'm wrong.


    Update:

    I tried this exact method and the task completes immediately. It didn't wait for switch to actually come alive. 

    Thank you


    .​


  • 8.  RE: Ansible Reboot Playbook

    Posted Dec 04, 2022 02:26 AM
    Update Again:


    I think I found the quick fix, by suppressing that failed task. Since the task is rebooting the device and somehow, ansible is "kind of stuck in the reboot task", suppressing the error on "reboot task" will allow subsequent playbooks to proceed as normal showing system uptime.

        - name: Reboot switch
          aoscx_command:
             commands:
                  - command: 'boot system'
                    prompt:

                        - '.*\(y\/n\)\?.*'

                    answer:

                        -  y

           ignore_errors: True



    PS.
    I set the command_timeout to 300 seconds.
    I am still hoping for a much better approach to this.


  • 9.  RE: Ansible Reboot Playbook
    Best Answer

    EMPLOYEE
    Posted Dec 05, 2022 01:20 PM
    Hi @sudovim - Yes use aoscx_boot_firmware to reboot the switch using REST API - then the wait_for task to ensure the IP is reachable, then the "show vsf" command to verify the rest of the stack is up. The entire playbook could look like the following:
    - name: Reboot switch & verify it's online
      hosts: all
      collections:
        - arubanetworks.aoscx
      tasks:
        - name: Boot the switch
          aoscx_boot_firmware:
            partition_name: 'primary'
            #partition_name: 'secondary'
            # Decide which partition should be booted    
        - name: Wait for the switch to come online after reboot
          wait_for:
            host: "{{ ansible_host }}"
            port: 22
            sleep: 10
            timeout: 900
    - name: Verify stack is rebooted
      hosts: all
      collections:
        - arubanetworks.aoscx
      gather_facts: False
      vars:
        ansible_connection: network_cli
      tasks:
        - name: Wait for Standby to join stack by entering Show vsf
          aoscx_command:
            commands:
              - 'show vsf'
            wait_for:
              - result[0] contains "Standby"
              #- result[0] contains "Member"
            match: all
            retries: 20
            interval: 5