Files
test/roles/ensure_os_upgrade/tasks/main.yml
T

115 lines
4.1 KiB
YAML

---
# tasks file for ensure_os_upgrade
- name: Include Variables
when: ["ansible_facts[\"system\"] == 'Linux'"]
ansible.builtin.include_vars:
file: '{{ lookup("first_found", findme) }}'
name: ensure_os_upgrade
vars:
findme:
files:
- '{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"]
}}-{{ ansible_facts["architecture"] }}.yml'
- '{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"]
}}-default.yml'
- '{{ ansible_facts["distribution"] }}-default.yml'
- '{{ ansible_facts["os_family"] }}-{{ ansible_facts["distribution_major_version"]
}}-{{ ansible_facts["architecture"] }}.yml'
- '{{ ansible_facts["os_family"] }}-{{ ansible_facts["distribution_major_version"]
}}-default.yml'
- '{{ ansible_facts["os_family"] }}-default.yml'
- default.yml
paths: [../vars/]
errors: ignore
- name: Package Discovery
when:
- ansible_facts["system"] == 'Linux'
- ansible_facts["packages"] is not defined
ansible.builtin.package_facts:
- name: Service Discovery
when:
- ansible_facts["system"] == 'Linux'
- ansible_facts["services"] is not defined
ansible.builtin.service_facts:
- name: Ensure Packages
when:
- ansible_facts["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_facts["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_facts["system"] == 'Linux'
- ansible_facts["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_facts["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_facts["system"] == 'Linux'
- ansible_facts["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_facts["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_facts["system"] == 'Linux'
- ansible_facts["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_facts["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
ansible.builtin.meta: flush_handlers