2022-10-11 09:18:51 +02:00
|
|
|
---
|
2023-09-24 09:12:28 +02:00
|
|
|
- name: Allow default HTTP traffic
|
2022-10-11 09:18:51 +02:00
|
|
|
ufw:
|
|
|
|
rule: allow
|
2023-09-24 08:49:05 +02:00
|
|
|
port: "{{ web_port }}"
|
2022-10-11 09:18:51 +02:00
|
|
|
|
2023-09-24 09:12:28 +02:00
|
|
|
- name: Allow HTTP traffic for vhosts
|
|
|
|
ufw:
|
|
|
|
rule: allow
|
2023-09-26 08:42:43 +02:00
|
|
|
port: "{{ item.web_port | default(80) }}"
|
2023-09-24 09:12:28 +02:00
|
|
|
loop: "{{ vhosts }}"
|
|
|
|
|
|
|
|
- name: Allow HTTPS default traffic
|
2022-10-11 09:18:51 +02:00
|
|
|
ufw:
|
|
|
|
rule: allow
|
2023-09-24 08:49:05 +02:00
|
|
|
port: "{{ ssl_port | default(443) }}"
|
2023-09-24 09:12:28 +02:00
|
|
|
when:
|
|
|
|
- ssl
|
|
|
|
|
|
|
|
- name: Allow HTTPS traffic for vhosts
|
|
|
|
ufw:
|
|
|
|
rule: allow
|
|
|
|
port: "{{ item.ssl_port | default(443) }}"
|
|
|
|
loop: "{{ vhosts }}"
|
|
|
|
when:
|
|
|
|
- ssl
|
2023-09-26 08:45:39 +02:00
|
|
|
- "'ssl' in item"
|
2023-09-24 09:12:28 +02:00
|
|
|
- item.ssl
|
2022-10-11 09:18:51 +02:00
|
|
|
|
2023-02-10 12:01:01 +01:00
|
|
|
- name: Ensure MPM Worker module is disabled
|
|
|
|
shell: a2dismod mpm_worker
|
|
|
|
|
2023-02-11 13:58:39 +01:00
|
|
|
- name: Ensure MPM Event module is disabled
|
|
|
|
shell: a2dismod mpm_event
|
2023-02-10 12:01:01 +01:00
|
|
|
|
2023-02-11 13:58:39 +01:00
|
|
|
- name: Ensure MPM Pre-Fork module is enabled
|
|
|
|
shell: a2enmod mpm_prefork
|
2023-02-08 20:09:31 +01:00
|
|
|
|
2022-10-11 09:18:51 +02:00
|
|
|
- name: Enable Apache2 modules
|
|
|
|
community.general.apache2_module:
|
|
|
|
state: present
|
|
|
|
name: "{{ item }}"
|
|
|
|
loop:
|
|
|
|
- rewrite
|
|
|
|
- ssl
|
2023-02-10 13:42:51 +01:00
|
|
|
- proxy_fcgi
|
2023-02-10 13:55:08 +01:00
|
|
|
- proxy
|
2023-02-06 13:33:12 +01:00
|
|
|
|
2022-10-11 09:18:51 +02:00
|
|
|
|
|
|
|
- name: Ensure default vhost root exists
|
|
|
|
file:
|
|
|
|
path: /var/www/html
|
|
|
|
state: directory
|
|
|
|
owner: www-data
|
|
|
|
group: www-data
|
|
|
|
mode: 0775
|
|
|
|
|
|
|
|
- name: Ensure default vhost is configured with SSL redirection
|
|
|
|
copy:
|
|
|
|
dest: /etc/apache2/conf-available/default_host.conf
|
|
|
|
src: files/default_host.conf
|
|
|
|
backup: yes
|
|
|
|
mode: 0644
|
|
|
|
notify:
|
|
|
|
- Restart Apache
|
|
|
|
|
|
|
|
- name: Ensure default vhost is enabled with SSL redirection
|
|
|
|
file:
|
|
|
|
dest: /etc/apache2/conf-enabled/default_host.conf
|
|
|
|
src: /etc/apache2/conf-available/default_host.conf
|
|
|
|
state: link
|
|
|
|
mode: 0644
|
|
|
|
notify:
|
|
|
|
- Restart Apache
|
|
|
|
|
|
|
|
- name: Ensure Apache modules are enabled
|
|
|
|
community.general.apache2_module:
|
|
|
|
state: present
|
|
|
|
force: True
|
|
|
|
name: "{{ item }}"
|
2023-09-24 08:49:05 +02:00
|
|
|
loop: "{{ apache_modules }}"
|
2023-02-08 20:28:05 +01:00
|
|
|
register: enabled_mods
|
2022-10-11 09:18:51 +02:00
|
|
|
when: apache_modules is defined
|
|
|
|
|
2023-02-08 20:28:05 +01:00
|
|
|
- name: Ensure Apache is restarted after enabling modules
|
|
|
|
service:
|
|
|
|
name: apache2
|
|
|
|
state: restarted
|
|
|
|
when: enabled_mods.changed
|
|
|
|
|
2022-10-11 09:18:51 +02:00
|
|
|
- name: Ensure vhost docroot exists
|
|
|
|
file:
|
2022-12-07 13:11:15 +01:00
|
|
|
path: "{{ item.docroot | default('/var/www/{{ item.vhostname }}') }}"
|
2022-10-11 09:18:51 +02:00
|
|
|
state: directory
|
|
|
|
owner: www-data
|
|
|
|
group: www-data
|
|
|
|
mode: 0775
|
|
|
|
loop: "{{ vhosts }}"
|
|
|
|
|
|
|
|
- name: Ensure vhosts are configured
|
|
|
|
template:
|
|
|
|
src: templates/vhost.conf.j2
|
2022-12-07 13:17:20 +01:00
|
|
|
dest: "/etc/apache2/sites-available/{{ item.weight | default('25') }}-{{ item.vhostname }}.conf"
|
2022-10-11 09:18:51 +02:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
backup: yes
|
|
|
|
with_items: "{{ vhosts }}"
|
|
|
|
notify:
|
|
|
|
- Restart Apache
|
|
|
|
|
|
|
|
- name: Ensure vhost is enabled
|
|
|
|
file:
|
2022-12-07 13:15:01 +01:00
|
|
|
src: "/etc/apache2/sites-available/{{ item.weight | default('25') }}-{{ item.vhostname }}.conf"
|
|
|
|
dest: "/etc/apache2/sites-enabled/{{ item.weight | default('25') }}-{{ item.vhostname }}.conf"
|
2022-10-11 09:18:51 +02:00
|
|
|
state: link
|
|
|
|
with_items: "{{ vhosts }}"
|
|
|
|
notify:
|
|
|
|
- Restart Apache
|