ansible-collection-webserver/roles/apache2/tasks/config.yml
s3lph 08da6c3a9d
Some checks failed
Ansible Lint / build (push) Has been cancelled
feat: add global ssl config
2024-08-11 04:01:35 +02:00

80 lines
2.6 KiB
YAML

---
- name: Enable Apache2 modules
community.general.apache2_module:
name: "{{ item }}"
loop: "{{ apache2_modules }}"
notify: Restart Apache2
- name: Flush handlers
ansible.builtin.meta: flush_handlers
- name: Check for TLS keypair existence
ansible.builtin.stat:
path: "{{ item }}"
follow: true
loop: |
{%- set files = [] -%}
{%- for name, site in apache2_sites.items() -%}
{%- if site.https_enabled | default(apache2_vhost_https_enabled) -%}
{%- set _x = files.append(site.tls_certfile | default(apache2_tls_certfile)) -%}
{%- set _x = files.append(site.tls_keyfile | default(apache2_tls_keyfile)) -%}
{%- endif -%}
{%- endfor -%}
{{- files | unique | list -}}
register: apache2_register_stat_tls_keypairs
- name: Create Apache2 document roots
ansible.builtin.file:
path: "{{ item.documentroot | default(apache2_vhost_documentroot) }}"
state: directory
owner: "{{ item.documentroot_owner | default(apache2_vhost_documentroot_owner) }}"
group: "{{ item.documentroot_group | default(apache2_vhost_documentroot_group) }}"
mode: "0755"
loop: "{{ apache2_sites.values() }}"
- name: Render Apache2 site configs
ansible.builtin.template:
src: etc/apache2/sites-available/site.conf.j2
dest: "/etc/apache2/sites-available/{{ item.key }}.conf"
owner: root
group: root
mode: "0644"
vars:
site_name: "{{ item.key }}"
site: "{{ item.value }}"
certfile_name: "{{ item.value.tls_certfile | default(apache2_tls_certfile) }}"
keyfile_name: "{{ item.value.tls_certfile | default(apache2_tls_keyfile) }}"
certfile_exists: "{{ (apache2_register_stat_tls_keypairs.results | selectattr('item', 'equalto', certfile_name))[0].stat.exists }}"
keyfile_exists: "{{ (apache2_register_stat_tls_keypairs.results | selectattr('item', 'equalto', keyfile_name))[0].stat.exists }}"
loop: "{{ apache2_sites | dict2items }}"
notify: Reload Apache2
- name: Enable Apache2 sites
ansible.builtin.file:
path: "/etc/apache2/sites-enabled/{{ item }}.conf"
state: link
src: "../sites-available/{{ item }}.conf"
owner: root
group: root
loop: "{{ apache2_sites.keys() }}"
notify: Reload apache2
- name: Render Apache2 global config
ansible.builtin.template:
src: etc/apache2/conf-available/99-sslconfig.conf.j2
dest: /etc/apache2/conf-available/99-sslconfig.conf
owner: root
group: root
mode: "0644"
notify: Reload apache2
- name: Enable Apache2 global config
ansible.builtin.file:
path: "/etc/apache2/conf-enabled/99-sslconfig.conf"
state: link
src: "../conf-available/99-sslconfig.conf"
owner: root
group: root
notify: Reload apache2