Roles only run on intended supported OS, and minor cleanup of when statements to match
This commit is contained in:
@@ -1,7 +1,17 @@
|
||||
---
|
||||
# tasks file for ensure_os_patch
|
||||
- name: Assert Target OS Is Supported
|
||||
when:
|
||||
- ansible_facts["system"] is defined
|
||||
ansible.builtin.assert:
|
||||
fail_msg: "Unsupported OS: {{ ansible_facts['distribution'] | default('unknown') }}"
|
||||
quiet: true
|
||||
that:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- >-
|
||||
ansible_facts["distribution"] in ['AlmaLinux', 'CentOS', 'Debian',
|
||||
'Fedora', 'OracleLinux', 'Rocky', 'Ubuntu']
|
||||
- name: Include Variables
|
||||
when: ["ansible_facts[\"system\"] == 'Linux'"]
|
||||
ansible.builtin.include_vars:
|
||||
file: '{{ lookup("first_found", findme) }}'
|
||||
name: ensure_os_patch
|
||||
@@ -23,17 +33,14 @@
|
||||
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_patch is defined
|
||||
- ensure_os_patch.package_list is defined
|
||||
- ensure_os_patch.package_list is iterable
|
||||
@@ -46,7 +53,6 @@
|
||||
notify: [Ensure_Os_Patch.Package_Facts, Ensure_Os_Patch.Service_Facts]
|
||||
- name: Ensure Apt Patch
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["pkg_mgr"] == 'apt'
|
||||
ansible.builtin.apt:
|
||||
autoclean: 'yes'
|
||||
@@ -56,7 +62,6 @@
|
||||
notify: [Ensure_Os_Patch.Package_Facts, Ensure_Os_Patch.Service_Facts]
|
||||
- name: Ensure Dnf
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["pkg_mgr"] == 'dnf'
|
||||
ansible.builtin.dnf:
|
||||
name: '*'
|
||||
@@ -65,7 +70,6 @@
|
||||
notify: [Ensure_Os_Patch.Package_Facts, Ensure_Os_Patch.Service_Facts]
|
||||
- name: Ensure Dnf5
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ansible_facts["pkg_mgr"] == 'dnf5'
|
||||
ansible.builtin.dnf5:
|
||||
name: '*'
|
||||
@@ -74,7 +78,6 @@
|
||||
notify: [Ensure_Os_Patch.Package_Facts, Ensure_Os_Patch.Service_Facts]
|
||||
- name: Ensure Services
|
||||
when:
|
||||
- ansible_facts["system"] == 'Linux'
|
||||
- ensure_os_patch is defined
|
||||
- ensure_os_patch.service_list is defined
|
||||
- ensure_os_patch.service_list is iterable
|
||||
@@ -88,3 +91,22 @@
|
||||
notify: [Ensure_Os_Patch.Package_Facts, Ensure_Os_Patch.Service_Facts]
|
||||
- name: Flush Handlers
|
||||
ansible.builtin.meta: flush_handlers
|
||||
- name: Post Verification Package Discovery
|
||||
when:
|
||||
- ensure_os_patch is defined
|
||||
- ensure_os_patch.package_list is defined
|
||||
- ensure_os_patch.package_list is iterable
|
||||
ansible.builtin.package_facts:
|
||||
- name: Assert Managed Packages Are Installed
|
||||
when:
|
||||
- ensure_os_patch is defined
|
||||
- ensure_os_patch.package_list is defined
|
||||
- ensure_os_patch.package_list is iterable
|
||||
ansible.builtin.assert:
|
||||
fail_msg: "Package {{ item.name }} is not installed"
|
||||
quiet: true
|
||||
that:
|
||||
- item.state != 'present' or ansible_facts['packages'][item.name] is defined
|
||||
loop: "{{ ensure_os_patch.package_list }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }} will be verified"
|
||||
|
||||
Reference in New Issue
Block a user