apache-precheck/apache-precheck.yml
2024-07-25 11:38:45 -04:00

60 lines
1.9 KiB
YAML

---
- name: Apache Pre-Check
hosts: all
become: true
gather_facts: true
vars_files:
- httpd.yml
tasks:
- name: Check if Middleware Apache package is present
ansible.builtin.package:
name: "{{ mw_apache_pkg }}"
state: present
check_mode: true
changed_when: false
register: mw_apache_pkg_check
- name: Verify Middleware Apache package and process presence
block:
- name: Assert that Middleware Apache package is present
ansible.builtin.assert:
that: mw_apache_pkg_check['results'] | length == 0
success_msg: Middleware Apache is installed on this host.
fail_msg: Middleware Apache is NOT installed on this host.
- name: Set Middleware Apache presence flag
ansible.builtin.set_stats:
data:
mw_apache_is_installed: true
rescue:
- name: Set Middleware Apache presence flag
ansible.builtin.set_stats:
data:
mw_apache_is_installed: false
- name: Verify if Middleware Apache process is running
when: mw_apache_pkg_check['results'] | length == 0
block:
- name: Check if any Middleware Apache processes are running
community.general.pids:
name: "{{ mw_apache_bin }}"
register: mw_apache_pids
- name: Assert that Middleware Apache process is running
ansible.builtin.assert:
that: mw_apache_pids['pids'] | length >= 2
success_msg: Middleware Apache is running on this host.
fail_msg: Middleware Apache is NOT running on this host.
- name: Set Middleware Apache process running flag
ansible.builtin.set_stats:
data:
mw_apache_is_running: true
rescue:
- name: Set Middleware Apache process running flag
ansible.builtin.set_stats:
data:
mw_apache_is_running: false