73 lines
2.6 KiB
YAML
73 lines
2.6 KiB
YAML
# This file is copied from atomic-host-tests
|
|
|
|
# vim: set ft=ansible:
|
|
# There is no clean way to restart hosts in ansible. The general issue is that
|
|
# the shutdown command may close sshd before ansible has time to "return" from
|
|
# the task, even with async & poll. This is due to the fact that asynchronous
|
|
# tasks still require a small synchronous bootstrapping script which takes 1 sec
|
|
# to complete, during which it is vulnerable to erroring out if sshd dies.
|
|
# To mitigate this, we prefix a sleep command before the shutdown so
|
|
# ansible has time to move on. For more info on this issue, see:
|
|
# https://github.com/ansible/ansible/issues/10616
|
|
#
|
|
# The Ansible docs now recommend this combination of tasks to handle reboots
|
|
# https://support.ansible.com/hc/en-us/articles/201958037-Reboot-a-server-and-wait-for-it-to-come-back
|
|
|
|
# remember the real ansible_host for following local actions
|
|
# (otherwise ansible will target the localhost)
|
|
- set_fact:
|
|
real_ansible_host: "{{ ansible_host }}"
|
|
timeout: "{{ cli_reboot_timeout | default('120') }}"
|
|
|
|
# Have to account for both because Fedora STR uses the old version of these
|
|
# inventory values for some reason.
|
|
- when: ansible_port is defined
|
|
set_fact:
|
|
real_ansible_port: "{{ ansible_port }}"
|
|
|
|
- when: ansible_ssh_port is defined
|
|
set_fact:
|
|
real_ansible_port: "{{ ansible_ssh_port }}"
|
|
|
|
- name: Get original bootid
|
|
command: cat /proc/sys/kernel/random/boot_id
|
|
register: orig_bootid
|
|
|
|
# Stop sshd (thus preventing new connections) and kill our current user's
|
|
# connection so that we can't race to get back in to the system while it's
|
|
# shutting down
|
|
- name: restart hosts
|
|
when: (not skip_shutdown is defined) or (not skip_shutdown)
|
|
shell: |
|
|
systemctl stop sshd
|
|
systemd-run --on-active=5 systemctl reboot
|
|
async: 1
|
|
poll: 0
|
|
ignore_errors: true
|
|
|
|
# NB: The wait_for is executed locally and doesn't require privs, so avoid sudo
|
|
- debug:
|
|
msg: "Waiting for reboot: {{ ansible_date_time.iso8601 }}"
|
|
- wait_for_connection:
|
|
delay: 5
|
|
timeout: 120
|
|
search_regex: "OpenSSH"
|
|
- debug:
|
|
msg: "SSH port is up {{ ansible_date_time.iso8601 }}"
|
|
|
|
- name: Assert that the bootid changed
|
|
command: cat /proc/sys/kernel/random/boot_id
|
|
register: new_bootid
|
|
until: new_bootid.stdout != orig_bootid.stdout
|
|
- assert:
|
|
that:
|
|
- new_bootid.stdout != orig_bootid.stdout
|
|
|
|
# provide an empty iterator when a list is not provided
|
|
# http://docs.ansible.com/ansible/playbooks_conditionals.html#loops-and-conditionals
|
|
- name: check services have started
|
|
service:
|
|
name: "{{ item }}"
|
|
state: started
|
|
with_items: "{{ wait_for_services|default([]) }}"
|