114 lines
3.8 KiB
YAML
114 lines
3.8 KiB
YAML
---
|
|
# tasks file for ensure_os_upgrade
|
|
- name: 'include variables'
|
|
when:
|
|
- ansible_system == 'Linux'
|
|
include_vars:
|
|
file: '{{ lookup("first_found", findme ) }}'
|
|
name: 'ensure_os_upgrade'
|
|
vars:
|
|
findme:
|
|
files:
|
|
- '{{ ansible_distribution }}-{{ ansible_distribution_major_version }}-{{ ansible_architecture }}.yml'
|
|
- '{{ ansible_distribution }}-{{ ansible_distribution_major_version }}-default.yml'
|
|
- '{{ ansible_distribution }}-default.yml'
|
|
- '{{ ansible_os_family }}-{{ ansible_distribution_major_version }}-{{ ansible_architecture }}.yml'
|
|
- '{{ ansible_os_family }}-{{ ansible_distribution_major_version }}-default.yml'
|
|
- '{{ ansible_os_family }}-default.yml'
|
|
- 'default.yml'
|
|
paths:
|
|
- '../vars/'
|
|
errors: 'ignore'
|
|
- name: 'package discovery'
|
|
when:
|
|
- ansible_system == 'Linux'
|
|
- packages is not defined
|
|
ansible.builtin.package_facts:
|
|
- name: 'service discovery'
|
|
when:
|
|
- ansible_system == 'Linux'
|
|
- services is not defined
|
|
ansible.builtin.service_facts:
|
|
- name: 'ensure packages'
|
|
when:
|
|
- ansible_system == 'Linux'
|
|
- ensure_os_upgrade is defined
|
|
- ensure_os_upgrade.package_list is defined
|
|
- ensure_os_upgrade.package_list is iterable
|
|
ansible.builtin.package:
|
|
name: '{{ item.name }}'
|
|
state: '{{ item.state }}'
|
|
loop: '{{ ensure_os_upgrade.package_list }}'
|
|
loop_control:
|
|
label: '{{ item.name }} will be {{ item.state }}'
|
|
notify:
|
|
- 'ensure_os_upgrade.package_facts'
|
|
- 'ensure_os_upgrade.service_facts'
|
|
- name: 'ensure services'
|
|
when:
|
|
- ansible_system == 'Linux'
|
|
- ensure_os_upgrade is defined
|
|
- ensure_os_upgrade.service_list is defined
|
|
- ensure_os_upgrade.service_list is iterable
|
|
ansible.builtin.service:
|
|
enabled: '{{ item.enabled }}'
|
|
name: '{{ item.name }}'
|
|
state: '{{ item.state }}'
|
|
loop: '{{ ensure_os_upgrade.service_list }}'
|
|
loop_control:
|
|
label: '{{ item.name }} will be {{ item.state }}'
|
|
notify:
|
|
- 'ensure_os_upgrade.package_facts'
|
|
- 'ensure_os_upgrade.service_facts'
|
|
- name: 'Ensure system-upgrade download'
|
|
when:
|
|
- ansible_system == 'Linux'
|
|
- ansible_distribution == 'Fedora'
|
|
- ensure_os_upgrade is defined
|
|
- ensure_os_upgrade.package_list is defined
|
|
- ensure_os_upgrade.package_list is iterable
|
|
- ensure_os_upgrade.target_version is defined
|
|
- ansible_distribution_major_version|int < ensure_os_upgrade.target_version|int
|
|
ansible.builtin.shell: >
|
|
dnf -y system-upgrade download --refresh --releasever={{ ensure_os_upgrade.target_version|int }}
|
|
- name: 'Ensure system-upgrade reboot'
|
|
when:
|
|
- ansible_system == 'Linux'
|
|
- ansible_distribution == 'Fedora'
|
|
- ensure_os_upgrade is defined
|
|
- ensure_os_upgrade.package_list is defined
|
|
- ensure_os_upgrade.package_list is iterable
|
|
- ensure_os_upgrade.target_version is defined
|
|
- ansible_distribution_major_version|int < ensure_os_upgrade.target_version|int
|
|
async: '1'
|
|
poll: '0'
|
|
ansible.builtin.shell: >
|
|
sleep 5 && dnf -y system-upgrade reboot
|
|
- name: 'Wait for the reboot'
|
|
when:
|
|
- ansible_system == 'Linux'
|
|
- ansible_distribution == 'Fedora'
|
|
- ensure_os_upgrade is defined
|
|
- ensure_os_upgrade.package_list is defined
|
|
- ensure_os_upgrade.package_list is iterable
|
|
- ensure_os_upgrade.target_version is defined
|
|
- ansible_distribution_major_version|int < ensure_os_upgrade.target_version|int
|
|
ansible.builtin.wait_for:
|
|
connect_timeout: '5'
|
|
delay: '300'
|
|
host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
|
|
port: '22'
|
|
search_regex: 'OpenSSH'
|
|
sleep: '15'
|
|
timeout: '1800'
|
|
vars:
|
|
ansible_connection: 'local'
|
|
- name: 'Gather facts'
|
|
ansible.builtin.setup:
|
|
notify:
|
|
- 'ensure_os_upgrade.package_facts'
|
|
- 'ensure_os_upgrade.service_facts'
|
|
- name: 'flush handlers'
|
|
meta: 'flush_handlers'
|
|
|