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.
96 lines
3.5 KiB
YAML
96 lines
3.5 KiB
YAML
---
|
|
# tasks file for ensure_os_upgrade
|
|
- 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_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["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_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:
|
|
- 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: Include Vendor / Version Specific Tasks
|
|
ansible.builtin.include_tasks:
|
|
file: '{{ lookup("first_found", findme) }}'
|
|
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
|
|
errors: ignore
|
|
- 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
|