arista.eos icon indicating copy to clipboard operation
arista.eos copied to clipboard

reload & meta

Open ryanmerolle opened this issue 3 years ago • 6 comments

SUMMARY

Per Rebooting Network Devices with Ansible @ipvsean mentions that the following should not fail the reboot task.

- reboot task (this is a snippet, full task removed for brevity)

- name: reset the connection
  meta: reset_connection

Yet when I set these 2 tasks to end my play, the task errors out.

- name: RELOAD DEVICE
  arista.eos.commands:
      - command: reload now force

- name: RESET CONNECTION
  meta: reset_connection

@ipvsean suggested I open an issue on this.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

arista.eos.commands

ANSIBLE VERSION
ansible 2.10.11
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/user1/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/user1/.local/lib/python3.8/site-packages/ansible
  executable location = /home/user1/.local/bin/ansible
  python version = 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0]
CONFIGURATION
<nothing>
OS / ENVIRONMENT

Ubuntu 20.04 Arista EOS 4.25.4M

STEPS TO REPRODUCE
- name: RELOAD DEVICE
  arista.eos.commands:
      - command: reload now force

- name: RESET CONNECTION
  meta: reset_connection
EXPECTED RESULTS

The task should not fail because of the rebooting device & ansible timeout

ACTUAL RESULTS

The task fails.

ryanmerolle avatar Jun 22 '21 22:06 ryanmerolle

@ryanmerolle Please add wait_for_connection task in between the RELOAD DEVICE and RESET CONNECTION tasks. wait_for_connection waits until the device is in usable state and then proceeds with the following tasks.

GomathiselviS avatar Jun 23 '21 14:06 GomathiselviS

Interesting.

I will test this shortly. Does that mean the article is wrong:

- reboot task (this is a snippet, full task removed for brevity)

- name: reset the connection
  meta: reset_connection

- name: Wait for the network device to reload
  wait_for_connection:
    delay: 10

ryanmerolle avatar Jun 29 '21 21:06 ryanmerolle

Hi @ryanmerolle: This is what worked for me:

 - name: Reload Device
   arista.eos.eos_command:
        commands: reload now
   ignore_errors: True

 - name: Wait for the connection
   wait_for:
        host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
        port: 22

 - name: reset the connection (OR replace this with any other following tasks to be done after reload)
   meta: reset_connection

Putting ignore_errors will ignore the error from reload command disconnection, and next task can wait for the connection to the device to be available again.

manuwelakanade avatar Aug 05 '21 10:08 manuwelakanade

@GomathiselviS I wrote the blog here, can you clarify?

IPvSean avatar Nov 19 '21 20:11 IPvSean

@IPvSean From what I tested on a local vm, once we give reload now command, it takes a few seconds to actually start rebooting. The reset connection task gets executed even before the device starts to reboot. That is why the reset_connection task needs to go after wait_for_connection.

GomathiselviS avatar Nov 22 '21 13:11 GomathiselviS

I am able to reboot a cisco ios network device with this->

    - name: reboot machine
      cisco.ios.ios_command:
        commands:
          - command: 'reload'
            prompt:
              - Proceed
            answer:
              - "y"

    - name: Wait for the network device to reload
      wait_for:
        host: "{{ ansible_host }}"
        delay: 40
        timeout: 600
        port: 22
      vars:
        ansible_connection: local

I will do some more testing... but this seems to work consistently, it takes like 5 minutes for IOS to reboot and it gets it

IPvSean avatar Sep 08 '22 21:09 IPvSean