From 26bb4e24d7b768385b2b549a7385601b67d828a9 Mon Sep 17 00:00:00 2001 From: Nazarii Hnydyn Date: Tue, 25 Jun 2019 21:28:48 +0000 Subject: [PATCH] Improved vms config reload: trigger only on state changed. Signed-off-by: Nazarii Hnydyn --- ansible/roles/eos/files/boot-config | 1 - .../handlers/common_handlers/update_state.yml | 20 +++++++++++ ansible/roles/eos/handlers/main.yml | 5 +++ ansible/roles/eos/tasks/main.yml | 33 ++++++------------- 4 files changed, 35 insertions(+), 24 deletions(-) create mode 100755 ansible/roles/eos/handlers/common_handlers/update_state.yml create mode 100755 ansible/roles/eos/handlers/main.yml diff --git a/ansible/roles/eos/files/boot-config b/ansible/roles/eos/files/boot-config index 9be9c2cf2cd..0565a4786e0 100644 --- a/ansible/roles/eos/files/boot-config +++ b/ansible/roles/eos/files/boot-config @@ -1,2 +1 @@ SWI=flash:/vEOS.swi - diff --git a/ansible/roles/eos/handlers/common_handlers/update_state.yml b/ansible/roles/eos/handlers/common_handlers/update_state.yml new file mode 100755 index 00000000000..fce6785b84d --- /dev/null +++ b/ansible/roles/eos/handlers/common_handlers/update_state.yml @@ -0,0 +1,20 @@ +- name: Reboot the VM + command: /sbin/shutdown -r now "Ansible updates triggered" + +- name: Wait for VM to shutdown + wait_for: + host: "{{ ansible_ssh_host }}" + port: 22 + state: stopped + delay: 10 + timeout: 300 + connection: local + +- name: Wait for VM to startup + wait_for: + host: "{{ ansible_ssh_host }}" + port: 22 + state: started + delay: 10 + timeout: 1200 + connection: local diff --git a/ansible/roles/eos/handlers/main.yml b/ansible/roles/eos/handlers/main.yml new file mode 100755 index 00000000000..fd86a76c7d6 --- /dev/null +++ b/ansible/roles/eos/handlers/main.yml @@ -0,0 +1,5 @@ +# Notify handlers are always run in the same order they are defined, not in the order listed in the notify-statement. +# This is also the case for handlers using listen. + +- name: Update VM state + include: roles/eos/handlers/common_handlers/update_state.yml diff --git a/ansible/roles/eos/tasks/main.yml b/ansible/roles/eos/tasks/main.yml index e3c64d6f805..50a148ac7be 100644 --- a/ansible/roles/eos/tasks/main.yml +++ b/ansible/roles/eos/tasks/main.yml @@ -41,34 +41,21 @@ set_fact: properties_list="{{ configuration[hostname]['properties'] }}" when: configuration and configuration[hostname] and configuration[hostname]['properties'] is defined -- name: copy boot-config - copy: src=boot-config - dest=/mnt/flash/boot-config - - name: Expand {{ hostname }} properties into props set_fact: props="{{ configuration_properties[item] | combine(props | default({})) }}" with_items: properties_list when: hostname in configuration and configuration_properties[item] is defined -- name: build a startup config - template: src="{{ topo }}-{{ props.swrole }}.j2" - dest=/mnt/flash/startup-config - when: hostname in configuration - -- name: Restart the box - command: /sbin/shutdown -r now "Ansible updates triggered" - when: hostname in configuration - -- name: Pause for reboot - pause: seconds=30 +- name: copy boot-config + copy: src=boot-config + dest=/mnt/flash/boot-config when: hostname in configuration + notify: + - Update VM state -- name: Wait for VM to come up - wait_for: - host: "{{ ansible_ssh_host }}" - port: 22 - state: started - delay: 10 - timeout: 600 - connection: local +- name: update startup-config + template: src="{{ topo }}-{{ props.swrole }}.j2" + dest=/mnt/flash/startup-config when: hostname in configuration + notify: + - Update VM state