amarao.reboot_if_needed_for_upgrade

Reboot If Needed for Upgrade

=========

This playbook will restart a server and wait for it to be back online. It will only restart if a reboot is necessary after an apt-get upgrade, indicated by the /var/run/reboot-required file.

Requirements


You need to be able to access the server directly via its IP address from the Ansible machine.

Changelog


  • Added a check to see if the port is reachable before attempting a reboot. To skip this check, use skip_pre_reboot_check=true.
  • Improved handling of SSH connection errors: Failed to connect to the host via ssh: Shared connection to 192.168.0.2 closed. Now it uses ansible_default_ipv4.address for better reliability.

Role Variables


This role checks if a specific port can be reached, reboots the server if requested (by apt or through a reboot flag), and waits until the port is available again.

It works only if you have direct access to the server. Usually, it checks the server’s status using ansible_default_ipv4.address. If you're unable to get the external IP, consult the role for getting external IP via DynDNS.

Variables:

  • ip_to_probe: The IP address to check (defaults to ansible_default_ipv4.address). It should be a valid IP or domain name, not an entry from your ssh_config.
  • port_to_probe: The port to check (defaults to 22, which is for SSH).
  • delay_before_probe: The waiting time after the reboot command (defaults to 10 seconds).
  • probe_timeout: The maximum time to wait (if ip_to_probe:port_to_probe doesn’t respond within this time, the role fails; default is 70 seconds).
  • force_reboot: Forces a reboot regardless of the reboot flag in /var/run/reboot-required (default is False).
  • reboot_delay: The waiting time before executing the reboot command (defaults to 2 seconds, to allow SSH to process).
  • reboot_flag: The file path for the reboot flag.
  • skip_pre_reboot_check: If set, skips the pre-reboot port check. Normally, the playbook will stop if it can't reach the port before rebooting.
  • pre_reboot_timeout: How long to wait for the port during the pre-reboot check.

Example Playbooks


Simple Example:

- hosts: servers
  vars:
    probe_timeout: 360
  roles:
    - amarao.reboot_if_needed_for_upgrade

Advanced Example:

- hosts: servers
  vars:
    port_to_probe: 2222
    ip_to_probe: "{{ ansible_ssh_host }}"
    delay_before_probe: 120
    probe_timeout: 360
    force_reboot: True
    skip_pre_reboot_check: true
  roles:
    - amarao.reboot_if_needed_for_upgrade

License


BSD

Author Information


(C) 2016-2019, servers.com, by George Shuklin

Informazioni sul progetto

Reboots if reboot is pending after apt-get upgrade (dist-upgrade) and waits until host returns back online.

Installa
ansible-galaxy install amarao.reboot_if_needed_for_upgrade
Licenza
Unknown
Download
195
Proprietario