quick_test/reboot_test copy.yml

74 lines
2.3 KiB
YAML

---
- name: Something
hosts: all
become: false
gather_facts: false
vars:
bootid_file: /proc/sys/kernel/random/boot_id
reboot_extra_time: 120
tasks:
- name: Capture initial boot ID
ansible.builtin.slurp:
src: "{{ bootid_file }}"
register: pre_reboot_boot_id_raw
- name: Set pre-reboot boot ID
ansible.builtin.set_fact:
pre_reboot_boot_id: "{{ pre_reboot_boot_id_raw['content'] | b64decode | trim }}"
# - name: Reboot the host
# ansible.builtin.reboot:
# reboot_timeout: 300
# post_reboot_delay: 30
# test_command: uptime
- name: Reboot the host
ansible.builtin.command:
cmd: "/usr/sbin/shutdown -r +1 '*** ANSIBLE INITIATED REBOOT ***'"
- name: Wait for connection
ansible.builtin.wait_for_connection:
connect_timeout: 20
sleep: 10
delay: 70
timeout: 1800
- name: Capture boot ID post reboot
ansible.builtin.slurp:
src: "{{ bootid_file }}"
register: post_reboot_boot_id_raw
- name: Set post-reboot boot ID
ansible.builtin.set_fact:
post_reboot_boot_id: "{{ post_reboot_boot_id_raw['content'] | b64decode | trim }}"
- name: Verify reboot status of host
block:
- name: Assert that the system has rebooted
ansible.builtin.assert:
that: pre_reboot_boot_id != post_reboot_boot_id
success_msg: "System rebooted successfully. Boot ID's differ."
fail_msg: "System did not reboot. Boot ID's match"
rescue:
- name: Giving the host extra time to complete its reboot
ansible.builtin.pause:
seconds: "{{ reboot_extra_time }}"
- name: Capture boot ID post reboot
ansible.builtin.slurp:
src: "{{ bootid_file }}"
register: post_reboot_boot_id_raw
- name: Set post-reboot boot ID
ansible.builtin.set_fact:
post_reboot_boot_id: "{{ post_reboot_boot_id_raw['content'] | b64decode | trim }}"
- name: Assert that the system has rebooted
ansible.builtin.assert:
that: pre_reboot_boot_id != post_reboot_boot_id
success_msg: "System rebooted successfully. Boot ID's differ."
fail_msg: "System did not reboot. Boot ID's match"