From f224d9227a3ff30e93265e476fb4f2575bdf1b90 Mon Sep 17 00:00:00 2001 From: shell Date: Tue, 19 Nov 2024 18:37:19 +0100 Subject: [PATCH] Create more plays do enable and disable confs. --- README.md | 7 +++++++ defaults/main.yml | 6 ++++++ tasks/configure-Debian.yml | 38 +++++++++++++++++++++++++++----------- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 960036eb..0e50138e 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,13 @@ apache_options: "-Indexes +FollowSymLinks" The default values for the `AllowOverride` and `Options` directives for the `documentroot` directory of each vhost. A vhost can overwrite these values by specifying `allow_override` or `options`. +```yaml +apache_confs_enabled: [] +apache_confss_disabled: [] +``` + +Same as Apache mods. But this is for additional confs. The corresponding direcotry is `mods-available` inside the apache apache configuration directory. + ```yaml apache_mods_enabled: - rewrite diff --git a/defaults/main.yml b/defaults/main.yml index c1ecb504..d2888571 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -47,6 +47,12 @@ apache_mods_enabled: - ssl apache_mods_disabled: [] +# Enable additional configs +apache_confs_enabled: [] + +# Disable these configs +apache_confs_disabled: [] + # Set initial apache state. Recommended values: `started` or `stopped` apache_state: started diff --git a/tasks/configure-Debian.yml b/tasks/configure-Debian.yml index a72bd71c..23ef992e 100644 --- a/tasks/configure-Debian.yml +++ b/tasks/configure-Debian.yml @@ -1,58 +1,74 @@ --- - name: Configure Apache. - lineinfile: + ansible.builtin.lineinfile: dest: "{{ apache_server_root }}/ports.conf" regexp: "{{ item.regexp }}" line: "{{ item.line }}" state: present - mode: 0644 + mode: "0644" with_items: "{{ apache_ports_configuration_items }}" notify: restart apache - name: Enable Apache mods. - file: + ansible.builtin.file: src: "{{ apache_server_root }}/mods-available/{{ item }}.load" dest: "{{ apache_server_root }}/mods-enabled/{{ item }}.load" state: link - mode: 0644 + mode: "0644" with_items: "{{ apache_mods_enabled }}" notify: restart apache - name: Disable Apache mods. - file: + ansible.builtin.file: path: "{{ apache_server_root }}/mods-enabled/{{ item }}.load" state: absent with_items: "{{ apache_mods_disabled }}" notify: restart apache +- name: Enable Apache confs. + ansible.builtin.file: + src: "{{ apache_server_root }}/confs-available/{{ item }}.load" + dest: "{{ apache_server_root }}/confs-enabled/{{ item }}.load" + state: link + mode: "0644" + with_items: "{{ apache_confs_enabled }}" + notify: restart apache + +- name: Disable Apache confs.. + ansible.builtin.file: + path: "{{ apache_server_root }}/confs-enabled/{{ item }}.load" + state: absent + with_items: "{{ apache_confs_disabled }}" + notify: restart apache + - name: Check whether certificates defined in vhosts exist. - stat: "path={{ item.certificate_file }}" + ansible.builtin.stat: "path={{ item.certificate_file }}" register: apache_ssl_certificates with_items: "{{ apache_vhosts_ssl }}" no_log: "{{ apache_ssl_no_log }}" - name: Add apache vhosts configuration. - template: + ansible.builtin.template: src: "{{ apache_vhosts_template }}" dest: "{{ apache_conf_path }}/sites-available/{{ apache_vhosts_filename }}" owner: root group: root - mode: 0644 + mode: "0644" notify: restart apache when: apache_create_vhosts | bool - name: Add vhost symlink in sites-enabled. - file: + ansible.builtin.file: src: "{{ apache_conf_path }}/sites-available/{{ apache_vhosts_filename }}" dest: "{{ apache_conf_path }}/sites-enabled/{{ apache_vhosts_filename }}" state: link - mode: 0644 + mode: "0644" force: "{{ ansible_check_mode }}" notify: restart apache when: apache_create_vhosts | bool - name: Remove default vhost in sites-enabled. - file: + ansible.builtin.file: path: "{{ apache_conf_path }}/sites-enabled/{{ apache_default_vhost_filename }}" state: absent notify: restart apache