Eliminate post-verification discovery and assert tasks (service_facts and package_facts) across all 19 roles and align AGENTS.md. Ansible's built-in declarative modules (package, service) already enforce target state natively and abort execution immediately on failure. The subsequent assertion loops were redundant, added significant runtime overhead, and produced false positives on non-service systemd units (.socket, .timer) and service aliases (e.g., dbus.socket failing under service_facts). - Remove service_facts and Assert Managed Services Are Active across 11 service roles (ensure_apache, ensure_cockpit, ensure_dbus, ensure_dovecot, ensure_fail2ban, ensure_firewalld, ensure_gitea, ensure_mariadb, ensure_podman, ensure_postfix, ensure_timezone). - Remove package_facts and Assert Managed Packages Are Installed across 8 package roles (ensure_ansible_prereq, ensure_git, ensure_os_patch, ensure_os_upgrade, ensure_repo_epel, ensure_repo_rpmfusion, ensure_rsync, ensure_vim). - Update AGENTS.md Section 8.2, Section 10, and Section 21 to codify declarative state enforcement and prohibit redundant post-task assertion loops.
94 lines
3.1 KiB
YAML
94 lines
3.1 KiB
YAML
---
|
|
# 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
|
|
ansible.builtin.include_vars:
|
|
file: '{{ lookup("first_found", findme) }}'
|
|
name: ensure_os_patch
|
|
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["packages"] is not defined
|
|
ansible.builtin.package_facts:
|
|
- name: Service Discovery
|
|
when:
|
|
- ansible_facts["services"] is not defined
|
|
ansible.builtin.service_facts:
|
|
- name: Ensure Packages
|
|
when:
|
|
- ensure_os_patch is defined
|
|
- ensure_os_patch.package_list is defined
|
|
- ensure_os_patch.package_list is iterable
|
|
ansible.builtin.package:
|
|
name: '{{ item.name }}'
|
|
state: '{{ item.state }}'
|
|
loop: '{{ ensure_os_patch.package_list }}'
|
|
loop_control:
|
|
label: '{{ item.name }} will be {{ item.state }}'
|
|
notify: [Ensure_Os_Patch.Package_Facts, Ensure_Os_Patch.Service_Facts]
|
|
- name: Ensure Apt Patch
|
|
when:
|
|
- ansible_facts["pkg_mgr"] == 'apt'
|
|
ansible.builtin.apt:
|
|
autoclean: 'yes'
|
|
autoremove: 'yes'
|
|
update_cache: 'yes'
|
|
upgrade: dist
|
|
notify: [Ensure_Os_Patch.Package_Facts, Ensure_Os_Patch.Service_Facts]
|
|
- name: Ensure Dnf
|
|
when:
|
|
- ansible_facts["pkg_mgr"] == 'dnf'
|
|
ansible.builtin.dnf:
|
|
name: '*'
|
|
state: latest
|
|
update_cache: 'yes'
|
|
notify: [Ensure_Os_Patch.Package_Facts, Ensure_Os_Patch.Service_Facts]
|
|
- name: Ensure Dnf5
|
|
when:
|
|
- ansible_facts["pkg_mgr"] == 'dnf5'
|
|
ansible.builtin.dnf5:
|
|
name: '*'
|
|
state: latest
|
|
update_cache: 'yes'
|
|
notify: [Ensure_Os_Patch.Package_Facts, Ensure_Os_Patch.Service_Facts]
|
|
- name: Ensure Services
|
|
when:
|
|
- ensure_os_patch is defined
|
|
- ensure_os_patch.service_list is defined
|
|
- ensure_os_patch.service_list is iterable
|
|
ansible.builtin.service:
|
|
enabled: '{{ item.enabled }}'
|
|
name: '{{ item.name }}'
|
|
state: '{{ item.state }}'
|
|
loop: '{{ ensure_os_patch.service_list }}'
|
|
loop_control:
|
|
label: '{{ item.name }} will be {{ item.state }}'
|
|
notify: [Ensure_Os_Patch.Package_Facts, Ensure_Os_Patch.Service_Facts]
|
|
- name: Flush Handlers
|
|
ansible.builtin.meta: flush_handlers
|