0724\
This commit is contained in:
44
files/ansible-playbooks/restart-cloud-agent-long-wrapper.yml
Normal file
44
files/ansible-playbooks/restart-cloud-agent-long-wrapper.yml
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# restart-cloud-agent-wrapper.yml
|
||||||
|
# Phase 1: Subsystem -> NetBox sync for current inventory_hostname
|
||||||
|
# Phase 2: Restart cloud-agent on the device
|
||||||
|
|
||||||
|
- name: Phase 1 | Subsystem -> NetBox sync before cloud-agent restart
|
||||||
|
hosts: all
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- name: "Wrapper | Verify netbox_subsystem_ikejanum_recursive.py exists"
|
||||||
|
delegate_to: localhost
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: ./netbox_subsystem_ikejanum_recursive.py
|
||||||
|
register: subsystem_script
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: "Wrapper | Run netbox_subsystem_ikejanum_recursive.py for {{ inventory_hostname }}"
|
||||||
|
delegate_to: localhost
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
set -o pipefail
|
||||||
|
python3 -u ./netbox_subsystem_ikejanum_recursive.py "{{ inventory_hostname }}" 2>&1
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
register: subsystem_sync
|
||||||
|
changed_when: false
|
||||||
|
failed_when: false
|
||||||
|
when: subsystem_script.stat.exists | default(false)
|
||||||
|
|
||||||
|
- name: "Wrapper | Show subsystem sync result"
|
||||||
|
delegate_to: localhost
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg:
|
||||||
|
- "script_exists={{ subsystem_script.stat.exists | default(false) }}"
|
||||||
|
- "rc={{ subsystem_sync.rc | default('NA') }}"
|
||||||
|
- "stdout_lines={{ subsystem_sync.stdout_lines | default([]) }}"
|
||||||
|
- "stderr_lines={{ subsystem_sync.stderr_lines | default([]) }}"
|
||||||
|
- "raw stdout (joined): {{ subsystem_sync.stdout | default('') }}"
|
||||||
|
- "raw stderr (joined): {{ subsystem_sync.stderr | default('') }}"
|
||||||
|
when: subsystem_script.stat.exists | default(false)
|
||||||
|
|
||||||
|
- name: "Wrapper | Abort softly if script missing"
|
||||||
|
ansible.builtin.meta: end_host
|
||||||
|
when: not (subsystem_script.stat.exists | default(false))
|
||||||
|
|
||||||
|
- import_playbook: restart-cloud-agent-long.yml
|
||||||
Reference in New Issue
Block a user