first commit

This commit is contained in:
Ludovic Cartier
2025-09-23 16:06:56 +02:00
commit de96d3c2bb
10 changed files with 206 additions and 0 deletions

57
tasks/configure.yml Normal file
View File

@@ -0,0 +1,57 @@
---
- name: 'apache2 | update ports'
replace:
path: /etc/apache2/ports.conf
regexp: '^Listen 80'
replace: "Listen {{ apache2_listen_ip }}:{{ apache2_listen_port }}"
backup: yes
notify:
- apache2 restart
tags:
- apache2
- apache2_configure
- name: 'apache2 | configuration | defaults modules'
community.general.apache2_module:
name: "{{ item.module }}"
state: "{{ item.state }}"
ignore_configcheck: true
loop:
- module: headers
state: present
- module: rewrite
state: present
- module: proxy
state: present
- module: proxy_fcgi
state: present
- module: proxy_http
state: present
notify:
- apache2 restart
tags:
- apache2
- apache2_configure
- name: 'apache2 | configuration | create ACME directory'
file:
path: /var/www/letsencrypt/.well-known/acme-challenge/
state: directory
owner: www-data
group: www-data
mode: '0755'
tags:
- apache2
- apache2_configure
- name: 'apache2 | configuration | push ACME configuration'
copy:
src: 'acme.conf'
dest: /etc/apache2/conf-enabled
owner: root
mode: 644
notify:
- apache2 restart
tags:
- apache2
- apache2_configure

32
tasks/install.yml Normal file
View File

@@ -0,0 +1,32 @@
---
- name: "apache2 | apt update cache"
apt:
update_cache: yes
cache_valid_time: 86400
tags:
- apache2
- apache2_install
- name: "apache2 | install packages"
apt:
name: "{{ item }}"
update_cache: true
state: present
with_items:
- apache2
- apache2-bin
- apache2-data
- apache2-utils
register: is_apache2
tags:
- apache2
- apache2_install
- name: "apache2 | remove default vhost"
file:
path: "/etc/apache2/sites-enabled/000-default.conf"
state: absent
tags:
- apache2
- apache2_install

9
tasks/main.yml Normal file
View File

@@ -0,0 +1,9 @@
---
- name: "apache2 | installation"
include_tasks: install.yml
- name: "apache2 | custom configuration"
include_tasks: configure.yml
# - name: "apache2 | configure vhost"
# include_tasks: vhost.yml

65
tasks/vhost.yml Normal file
View File

@@ -0,0 +1,65 @@
---
- name: 'apache2 | vhost | configure vhosts'
template:
src: "{{ item.value.template | default('vhost.conf.j2') }}"
dest: "/etc/apache2/sites-available/{{ item.key }}.conf"
owner: root
group: root
mode: 0644
loop: "{{ apache2_vhosts | dict2items }}"
notify:
- apache2 reload
tags:
- apache2
- apache2_vhost
- name: 'apache2 | vhost | enable vhosts'
file:
src: "/etc/apache2/sites-available/{{ item.key }}.conf"
dest: "/etc/apache2/sites-enabled/{%if item.value.priority is defined%}{{ item.value.priority }}-{%endif%}{{ item.key }}.conf"
state: link
loop: "{{ apache2_vhosts | dict2items }}"
when: item.value.enabled is not defined or item.value.enabled
notify:
- apache2 reload
tags:
- apache2
- apache2_vhost
- name: 'apache2 | vhost | configure DocumentRoot'
file:
path: "{{ item.value.documentroot.path | default(apache2_documentroot_default) }}"
state: directory
owner: "{{ item.value.documentroot.user | default(apache2_user) }}"
group: "{{ item.value.documentroot.group | default(apache2_group) }}"
loop: "{{ apache2_vhosts | dict2items }}"
loop_control:
label: "{{ item.value.documentroot | default([]) }}"
when:
- item.value.enabled is undefined or item.value.enabled
- item.value.documentroot is defined
- item.value.documentroot != False
notify:
- apache2 reload
tags:
- apache2
- apache2_vhost
- name: 'apache2 | vhost | configure logs directory'
file:
path: "/var/log/apache2/{{ item.value.servername }}"
state: directory
owner: root
group: adm
loop: "{{ apache_vhosts | dict2items }}"
loop_control:
label: "{{ item.value.servername | default([]) }}"
when:
- item.value.enabled is undefined or item.value.enabled
- item.value.documentroot is defined
- item.value.documentroot != False
notify:
- apache2 reload
tags:
- apache2
- apache2_vhost