Files
test/roles/ensure_apache/tasks/main.yml
T
jmrothst 4078b0b064 refactor(roles): remove redundant post-task service and package assertions
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.
2026-09-07 23:34:19 -05:00

228 lines
7.5 KiB
YAML

---
# tasks file for ensure_apache
- 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_apache
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 Sysctl
when:
- ensure_apache is defined
- ensure_apache.sysctl_list is defined
- ensure_apache.sysctl_list is iterable
ansible.posix.sysctl:
name: '{{ item.name }}'
reload: '{{ item.reload | default(omit) }}'
state: '{{ item.state }}'
sysctl_file: '{{ item.sysctl_file | default(omit) }}'
sysctl_set: '{{ item.sysctl_set | default(omit) }}'
value: '{{ item.value | default(omit) }}'
loop: '{{ ensure_apache.sysctl_list }}'
loop_control:
label: '{{ item.name }} will be {{ item.value }}'
notify:
- Ensure_Apache.Package_Facts
- Ensure_Apache.Service_Facts
- Ensure_Apache.Service_Reload
- Ensure_Apache.Service_Reload_Config
- name: Ensure Packages
when:
- ensure_apache is defined
- ensure_apache.package_list is defined
- ensure_apache.package_list is iterable
ansible.builtin.package:
name: '{{ item.name }}'
state: '{{ item.state }}'
loop: '{{ ensure_apache.package_list }}'
loop_control:
label: '{{ item.name }} will be {{ item.state }}'
notify:
- Ensure_Apache.Package_Facts
- Ensure_Apache.Service_Facts
- Ensure_Apache.Service_Reload
- Ensure_Apache.Service_Reload_Config
- name: Ensure Seboolean
when:
- ensure_apache is defined
- ensure_apache.seboolean_list is defined
- ensure_apache.seboolean_list is iterable
ansible.posix.seboolean:
name: '{{ item.name }}'
persistent: '{{ item.persistent }}'
state: '{{ item.state }}'
loop: '{{ ensure_apache.seboolean_list }}'
loop_control:
label: '{{ item.name }} will be {{ item.state }}'
notify:
- Ensure_Apache.Package_Facts
- Ensure_Apache.Service_Facts
- Ensure_Apache.Service_Reload
- Ensure_Apache.Service_Reload_Config
- name: Ensure Configurations
when:
- http_vhost is defined
- ensure_apache is defined
- ensure_apache.template_list is defined
- ensure_apache.template_list is iterable
ansible.builtin.template:
backup: 'no'
dest: '{{ item.dest }}'
group: '{{ item.group | default(omit) }}'
mode: '{{ item.mode | default(omit) }}'
owner: '{{ item.owner | default(omit) }}'
selevel: '{{ item.selevel | default(omit) }}'
serole: '{{ item.serole | default(omit) }}'
setype: '{{ item.setype | default(omit) }}'
seuser: '{{ item.seuser | default(omit) }}'
src: '{{ item.src }}'
loop: '{{ ensure_apache.template_list }}'
loop_control:
label: '{{ item.dest }} will be ensured'
notify:
- Ensure_Apache.Package_Facts
- Ensure_Apache.Service_Facts
- Ensure_Apache.Service_Reload
- Ensure_Apache.Service_Reload_Config
- name: Ensure Firewall
when:
- ansible_facts.packages["firewalld"] is defined
- ansible_facts.packages["python3-firewall"] is defined
- ensure_apache is defined
- ensure_apache.firewalld_list is defined
- ensure_apache.firewalld_list is iterable
ansible.posix.firewalld:
permanent: '{{ item.permanent }}'
service: '{{ item.service }}'
state: '{{ item.state }}'
loop: '{{ ensure_apache.firewalld_list }}'
loop_control:
label: '{{ item.service }} will be {{ item.state }}'
notify:
- Ensure_Apache.Package_Facts
- Ensure_Apache.Service_Facts
- Ensure_Apache.Service_Reload
- Ensure_Apache.Service_Reload_Config
- name: Ensure Permissions
when:
- ensure_apache is defined
- http_vhost is defined
- http_vhost is iterable
- ensure_apache.permission_list is defined
- ensure_apache.permission_list is iterable
ansible.builtin.file:
attributes: '{{ item.attributes | default(omit) }}'
follow: '{{ item.follow | default(omit) }}'
force: '{{ item.force | default(omit) }}'
group: '{{ item.group | default(omit) }}'
owner: '{{ item.owner | default(omit) }}'
mode: '{{ item.mode | default(omit) }}'
path: '{{ item.path }}'
reuse: '{{ item.reuse | default(omit) }}'
selevel: '{{ item.selevel | default(omit) }}'
serole: '{{ item.serole | default(omit) }}'
setype: '{{ item.setype | default(omit) }}'
seuser: '{{ item.seuser | default(omit) }}'
src: '{{ item.src | default(omit) }}'
state: '{{ item.state }}'
loop: '{{ ensure_apache.permission_list }}'
loop_control:
label: '{{ item.path }} will be ensured'
notify:
- Ensure_Apache.Package_Facts
- Ensure_Apache.Service_Facts
- Ensure_Apache.Service_Reload
- Ensure_Apache.Service_Reload_Config
- name: Ensure Vhost Document Roots
when:
- ensure_apache is defined
- http_vhost is defined
- http_vhost is iterable
- item.fqdn is defined
ansible.builtin.file:
path: /srv/http/{{ item.fqdn }}
state: directory
owner: root
group: root
mode: '0755'
setype: httpd_sys_content_t
loop: '{{ http_vhost }}'
loop_control:
label: /srv/http/{{ item.fqdn }} will be ensured
notify:
- Ensure_Apache.Package_Facts
- Ensure_Apache.Service_Facts
- Ensure_Apache.Service_Reload
- Ensure_Apache.Service_Reload_Config
- name: Ensure Website Content From Git Repos
when:
- ensure_apache is defined
- http_vhost is defined
- http_vhost is iterable
- item.fqdn is defined
- item.repo is defined
ansible.builtin.git:
accept_hostkey: 'yes'
dest: /srv/http/{{ item.fqdn }}
repo: '{{ item.repo }}'
loop: '{{ http_vhost }}'
loop_control:
label: /srv/http/{{ item.fqdn }} will be populated...
notify:
- Ensure_Apache.Package_Facts
- Ensure_Apache.Service_Facts
- Ensure_Apache.Service_Reload
- Ensure_Apache.Service_Reload_Config
- name: Ensure Services
when:
- ensure_apache is defined
- ensure_apache.service_list is defined
- ensure_apache.service_list is iterable
ansible.builtin.service:
enabled: '{{ item.enabled }}'
name: '{{ item.name }}'
state: '{{ item.state }}'
loop: '{{ ensure_apache.service_list }}'
loop_control:
label: '{{ item.name }} will be {{ item.state }}'
notify:
- Ensure_Apache.Package_Facts
- Ensure_Apache.Service_Facts
- Ensure_Apache.Service_Reload
- Ensure_Apache.Service_Reload_Config
- name: Flush Handlers
ansible.builtin.meta: flush_handlers