ansible-collections / arista.eos

Ansible Network Collection for Arista EOS
GNU General Public License v3.0
82 stars 68 forks source link

reload & meta #227

Open ryanmerolle opened 3 years ago

ryanmerolle commented 3 years ago
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
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.

GomathiselviS commented 3 years ago

@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.

ryanmerolle commented 3 years ago

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
manuwelakanade commented 3 years ago

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.

IPvSean commented 2 years ago

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

GomathiselviS commented 2 years ago

@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.

IPvSean commented 2 years ago

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