ansible-development-environ.../roles/reboot/tasks/main.yml

63 lines
1.7 KiB
YAML

---
# tasks file for reboot
- name: install requirements
package:
name: "{{ reboot_requirements }}"
state: present
register: reboot_install_requirements
until: reboot_install_requirements is succeeded
retries: 3
- name: check for needs-restarting for rhel
stat:
path: /usr/bin/needs-restarting
register: reboot_check_for_needs_restarting_for_rhel
- name: check for needs-restarting for debian
stat:
path: /var/run/needs-restarting
register: reboot_check_for_needs_restarting_for_debian
- name: see if a reboot is required for rhel
command: "{{ reboot_needs_restarting_command }}"
register: needsrestarting
changed_when:
- needsrestarting.rc != 0
failed_when:
- needsrestarting.rc != 1
- needsrestarting.rc != 0
when:
- ansible_virtualization_type != "docker"
- reboot_check_for_needs_restarting_for_rhel.stat.exists
- not reboot_always | bool
- name: show reboot_check_for_needs_restarting_for_rhel.stat.exists
debug:
var: reboot_check_for_needs_restarting_for_rhel.stat.exists
- name: show needsrestarting.rc
debug:
var: needsrestarting.rc
- name: show reboot_check_for_needs_restarting_for_debian.stat.exists
debug:
var: reboot_check_for_needs_restarting_for_debian.stat.exists
- name: reboot the machine
shell: "(sleep {{ reboot_delay }} && {{ reboot_command }} &)"
async: 1
poll: 0
ignore_errors: yes
when:
- ansible_virtualization_type != "docker"
- (reboot_check_for_needs_restarting_for_rhel.stat.exists and
needsrestarting.rc == 1) or
reboot_check_for_needs_restarting_for_debian.stat.exists
notify:
- 1 wait for the start of reboot
- 2 wait for the machine to be up
- 3 gather facts after reboot
- name: flush handlers
meta: flush_handlers