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

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.vscode

9
LICENSE Normal file
View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) 2025 ansible-roles
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

6
defaults/main.yml Normal file
View File

@@ -0,0 +1,6 @@
---
apache2_listen_ip: 127.0.0.1
apache2_listen_port: 8080
apache2_user: www-data
apache2_group: www-data
apache2_documentroot_default: /var/www/html

6
files/acme.conf Normal file
View File

@@ -0,0 +1,6 @@
Alias /.well-known/acme-challenge/ /var/www/letsencrypt/.well-known/acme-challenge/
<Directory "/var/www/letsencrypt/.well-known/acme-challenge/">
Order allow,deny
Allow from all
</Directory>

12
handlers/main.yml Normal file
View File

@@ -0,0 +1,12 @@
---
- name: 'apache2 reload'
systemd:
name: apache2
state: reloaded
tags: ['apache2']
- name: 'apache2 restart'
systemd:
name: apache2
state: restarted
tags: ['apache2']

9
meta/main.yml Normal file
View File

@@ -0,0 +1,9 @@
---
galaxy_info:
author: Ludovic Cartier
description: install & configure apache2
company: brainsys
license: MIT
min_ansible_version: 2.8
issue_tracker_url: https://git.brainsys.io/ansible-roles/apache/issues
github_branch: main

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