diff --git a/tasks/check_config.yml b/tasks/check_config.yml new file mode 100644 index 0000000000000000000000000000000000000000..0b8baaf964c9969d7bf635b742b23c0a218ed93b --- /dev/null +++ b/tasks/check_config.yml @@ -0,0 +1,76 @@ +# Copyright 2018-2023 Chris Croome +# +# This file is part of the Webarchitects Apache Ansible role. +# +# The Webarchitects Apache Ansible role is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +# +# The Webarchitects Apache Ansible role is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with the Webarchitects Apache Ansible role. If not, see <https://www.gnu.org/licenses/>. +--- +- name: Check that config to be enabled exists + block: + + - name: Find the mods available + ansible.builtin.find: + paths: /etc/apache2/mods-available + file_type: file + use_regex: true + patterns: '^.*[.]load$' + recurse: false + register: apache_mods_available_paths + + - name: Set a fact for the mods available + ansible.builtin.set_fact: + apache_mods_available: "{{ apache_mods_available_paths | community.general.json_query('files[].path') | map('basename') | map('regex_replace', '[.]load$') | sort }}" + + - name: Debug the mods available + ansible.builtin.debug: + var: apache_mods_available + verbosity: 2 + + - name: Check that all mods to be enabled are available + ansible.builtin.assert: + that: + - apache_mods_enabled | difference(apache_mods_available) | length == 0 + fail_msg: "The follwing mode that are set to be enabled are not available:{% for apache_mod in apache_mods_enabled | difference(apache_mods_available) %} {{ apache_mod }}{% endfor %}" + + - name: Find the conf available + ansible.builtin.find: + paths: /etc/apache2/conf-available + file_type: file + use_regex: true + patterns: '^.*[.]conf$' + recurse: false + register: apache_conf_available_paths + + - name: Set a fact for the conf available + ansible.builtin.set_fact: + apache_conf_available: "{{ apache_conf_available_paths | community.general.json_query('files[].path') | map('basename') | map('regex_replace', '[.]conf$') | sort }}" + + - name: Debug the conf available + ansible.builtin.debug: + var: apache_conf_available + verbosity: 2 + + - name: Find the sites available + ansible.builtin.find: + paths: /etc/apache2/sites-available + file_type: file + use_regex: true + patterns: '^.*[.]conf$' + recurse: false + register: apache_sites_available_paths + + - name: Set a fact for the sites available + ansible.builtin.set_fact: + apache_sites_available: "{{ apache_sites_available_paths | community.general.json_query('files[].path') | map('basename') | map('regex_replace', '[.]conf$') | sort }}" + + - name: Debug the sites available + ansible.builtin.debug: + var: apache_sites_available + verbosity: 2 + + tags: + - apache +... diff --git a/tasks/checks.yml b/tasks/checks.yml index d9449c434487d3f34a17cd58eb72ae1360ccf55e..3a8bc1b297a9ae12db0687ed55ce3145c0629bd2 100644 --- a/tasks/checks.yml +++ b/tasks/checks.yml @@ -11,33 +11,6 @@ - name: Check that mistakes haven't been made in the variables and arrays block: - - name: Find the mods available - ansible.builtin.find: - paths: /etc/apache2/mods-available - file_type: file - use_regex: true - patterns: '^.*[.]load$' - recurse: false - register: apache_mods_available_load - - - name: Debug the mods available find output - ansible.builtin.debug: - var: apache_mods_available_load - verbosity: 2 - - - name: Set a fact for the mods available - ansible.builtin.set_fact: - apache_mods_available: "{{ apache_mods_available_load | community.general.json_query('files[].path') | map('basename') | map('regex_replace', '[.]load$') | sort }}" - # apache_mods_available: "{{ apache_mods_available_load | community.general.json_query('files[].path') }}" - - - name: Debug the mods available - ansible.builtin.debug: - var: apache_mods_available - verbosity: 2 - - - name: Debug fail - ansible.builtin.fail: - - name: Check that at least one module is in apache_mods_enabled and that either mpm_event or mpm_prefork is enabled ansible.builtin.assert: that: diff --git a/tasks/main.yml b/tasks/main.yml index 86b1f15141a275315795258554fd9b7f747ca9e5..d6ca049ae9807a905259da8a1e3eb5c5fc6d8e39 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -124,6 +124,9 @@ owner: root group: root + - name: Include Apache check config tasks + ansible.builtin.include_tasks: check_config.yml + - name: Apache modules disabled and enabled ansible.builtin.include_tasks: a2mod.yml when: ( apache_mods_disabled is defined ) or ( apache_mods_enabled is defined )