Initial project commit
This commit is contained in:
commit
991a810ac0
5
.ansible-lint
Normal file
5
.ansible-lint
Normal file
@ -0,0 +1,5 @@
|
||||
skip_list:
|
||||
- yaml[colons]
|
||||
- yaml[empty-lines]
|
||||
- yaml[line-length]
|
||||
- no-changed-when
|
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
||||
verified_reboot
|
||||
=========
|
||||
|
||||
This role will use proc's boot_id file to determine if a host has rebooted or not.
|
||||
|
||||
|
17
defaults/main.yml
Normal file
17
defaults/main.yml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
verified_reboot_reboot_time: 1 # Time in minutes issued to the shutdown command
|
||||
verified_reboot_reboot_msg: '*** ANSIBLE INITIATED REBOOT ***'
|
||||
verified_reboot_bootid_file: /proc/sys/kernel/random/boot_id
|
||||
verified_reboot_max_checks: 10
|
||||
|
||||
# Maximum number of seconds to wait for a connection to happen before closing and retrying.
|
||||
verified_reboot_wait_conn_timeout: 20
|
||||
|
||||
# Number of seconds to sleep between checks.
|
||||
verified_reboot_wait_sleep: 10
|
||||
|
||||
# Number of seconds to wait before starting to poll.
|
||||
verified_reboot_wait_delay: 70
|
||||
|
||||
# Maximum number of seconds to wait for.
|
||||
verified_reboot_wait_timeout: 1800
|
26
meta/main.yml
Normal file
26
meta/main.yml
Normal file
@ -0,0 +1,26 @@
|
||||
galaxy_info:
|
||||
author: Chris Hammer
|
||||
description: This role will use proc's boot_id file to determine if a host has rebooted or not.
|
||||
|
||||
# If the issue tracker for your role is not on github, uncomment the
|
||||
# next line and provide a value
|
||||
# issue_tracker_url: http://example.com/issue/tracker
|
||||
|
||||
# Choose a valid license ID from https://spdx.org - some suggested licenses:
|
||||
# - BSD-3-Clause (default)
|
||||
# - MIT
|
||||
# - GPL-2.0-or-later
|
||||
# - GPL-3.0-only
|
||||
# - Apache-2.0
|
||||
# - CC-BY-4.0
|
||||
license: BSD-3-Clause
|
||||
|
||||
min_ansible_version: "2.14"
|
||||
|
||||
platforms:
|
||||
- name: EL
|
||||
versions:
|
||||
- "7"
|
||||
- "8"
|
||||
- "9"
|
||||
|
38
tasks/check_boot_id.yml
Normal file
38
tasks/check_boot_id.yml
Normal file
@ -0,0 +1,38 @@
|
||||
---
|
||||
- name: Wait for connection to host
|
||||
ansible.builtin.wait_for_connection:
|
||||
connect_timeout: "{{ verified_reboot_wait_conn_timeout }}"
|
||||
sleep: "{{ verified_reboot_wait_sleep }}"
|
||||
delay: "{{ verified_reboot_wait_delay }}"
|
||||
timeout: "{{ verified_reboot_wait_timeout }}"
|
||||
|
||||
- name: Increment check count
|
||||
ansible.builtin.set_fact:
|
||||
verified_reboot_check_count:
|
||||
"{{ 1 if verified_reboot_check_count is undefined else verified_reboot_check_count | int + 1 }}"
|
||||
|
||||
- name: Capture post-reboot boot ID
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ verified_reboot_bootid_file }}"
|
||||
register: verified_reboot_post_boot_id_raw
|
||||
|
||||
- name: Set post-reboot boot ID
|
||||
ansible.builtin.set_fact:
|
||||
verified_reboot_post_boot_id: "{{ verified_reboot_post_boot_id_raw['content'] | b64decode | trim }}"
|
||||
|
||||
- name: Debug boot IDs
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ verified_reboot_pre_boot_id }} == {{ verified_reboot_post_boot_id }}"
|
||||
verbosity: 1
|
||||
|
||||
- name: Max check count exception
|
||||
ansible.builtin.fail:
|
||||
msg: "Max check count ({{ verified_reboot_max_checks }}) reached. Aborting."
|
||||
when:
|
||||
- verified_reboot_check_count | int >= verified_reboot_max_checks
|
||||
|
||||
- name: Re-check host reboot status
|
||||
ansible.builtin.include_tasks: check_boot_id.yml
|
||||
when:
|
||||
- verified_reboot_pre_boot_id == verified_reboot_post_boot_id
|
||||
- verified_reboot_check_count | int < verified_reboot_max_checks
|
16
tasks/main.yml
Normal file
16
tasks/main.yml
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
- name: Capture initial boot ID
|
||||
ansible.builtin.slurp:
|
||||
src: "{{ verified_reboot_bootid_file }}"
|
||||
register: verified_reboot_pre_boot_id_raw
|
||||
|
||||
- name: Set pre-reboot boot ID
|
||||
ansible.builtin.set_fact:
|
||||
verified_reboot_pre_boot_id: "{{ verified_reboot_pre_boot_id_raw['content'] | b64decode | trim }}"
|
||||
|
||||
- name: Reboot the host
|
||||
ansible.builtin.command:
|
||||
cmd: "/usr/sbin/shutdown -r +{{ verified_reboot_reboot_time }} '{{ verified_reboot_reboot_msg }}'"
|
||||
|
||||
- name: Verify reboot status of host
|
||||
ansible.builtin.include_tasks: check_boot_id.yml
|
Loading…
x
Reference in New Issue
Block a user