From e5a65b550c719f427e0bb46f2e3149092b9e6285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Gon=C3=A7alves?= Date: Mon, 1 Jan 2024 13:26:11 +0100 Subject: refactor(roles/httpd): merge httpd roles --- roles/httpd/defaults/main.yml | 14 ++++++++- roles/httpd/meta/main.yml | 7 ----- roles/httpd/tasks/main.yml | 26 ++++++++++++++++- roles/httpd/templates/httpd.conf.j2 | 17 ++++------- roles/httpd_pre/defaults/main.yml | 8 ----- roles/httpd_pre/tasks/main.yml | 24 --------------- roles/httpd_site_healthcheck/defaults/main.yml | 8 ----- roles/httpd_site_healthcheck/meta/main.yml | 5 ---- roles/httpd_site_healthcheck/tasks/main.yml | 25 ---------------- .../httpd_site_healthcheck/templates/httpd.conf.j2 | 6 ---- .../httpd_site_healthcheck/templates/index.html.j2 | 34 ---------------------- 11 files changed, 43 insertions(+), 131 deletions(-) delete mode 100644 roles/httpd/meta/main.yml delete mode 100644 roles/httpd_pre/defaults/main.yml delete mode 100644 roles/httpd_pre/tasks/main.yml delete mode 100644 roles/httpd_site_healthcheck/defaults/main.yml delete mode 100644 roles/httpd_site_healthcheck/meta/main.yml delete mode 100644 roles/httpd_site_healthcheck/tasks/main.yml delete mode 100644 roles/httpd_site_healthcheck/templates/httpd.conf.j2 delete mode 100644 roles/httpd_site_healthcheck/templates/index.html.j2 diff --git a/roles/httpd/defaults/main.yml b/roles/httpd/defaults/main.yml index 3b0acd0..f5e0a43 100644 --- a/roles/httpd/defaults/main.yml +++ b/roles/httpd/defaults/main.yml @@ -2,7 +2,19 @@ httpd_configuration_file: /etc/httpd.conf httpd_configuration_dir: /etc/httpd.d -httpd_chroot: /var/www +httpd_chroot_dir: /var/www +httpd_passwords_dir: "{{ httpd_chroot_dir }}/htpasswd" +httpd_sites_dir: "{{ httpd_chroot_dir }}/htdocs" httpd_user: www httpd_group: www + +httpd_supported_types: + - application/xml xml rss + - image/gif gif + - image/jpeg jpeg jpg + - image/png png + - image/svg+xml svg + - text/css css + - text/html html htm + - text/plain txt pgp pub diff --git a/roles/httpd/meta/main.yml b/roles/httpd/meta/main.yml deleted file mode 100644 index 161e3b8..0000000 --- a/roles/httpd/meta/main.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- - -dependencies: - - role: httpd_pre - tags: dependency - - role: httpd_site_healthcheck - tags: dependency diff --git a/roles/httpd/tasks/main.yml b/roles/httpd/tasks/main.yml index f946044..584ae0b 100644 --- a/roles/httpd/tasks/main.yml +++ b/roles/httpd/tasks/main.yml @@ -1,10 +1,34 @@ --- +- name: create httpd directory + ansible.builtin.file: + path: "{{ httpd_configuration_dir }}" + state: directory + owner: 0 + group: 0 + mode: "0644" + +- name: create passwords directory + ansible.builtin.file: + path: "{{ httpd_passwords_dir }}" + state: directory + owner: "{{ httpd_user }}" + group: "{{ httpd_group }}" + mode: "0700" + +- name: create sites directory + ansible.builtin.file: + path: "{{ httpd_sites_dir }}" + state: directory + owner: 0 + group: 0 + mode: "0755" + - name: retrieve all configuration files ansible.builtin.find: path: "{{ httpd_configuration_dir }}" patterns: "*.conf" - register: configuration_files + register: httpd_configuration_files - name: generate httpd configuration ansible.builtin.template: diff --git a/roles/httpd/templates/httpd.conf.j2 b/roles/httpd/templates/httpd.conf.j2 index 6285d70..49e928d 100644 --- a/roles/httpd/templates/httpd.conf.j2 +++ b/roles/httpd/templates/httpd.conf.j2 @@ -1,18 +1,12 @@ # managed by Ansible types { - text/css css - text/html html htm - text/plain txt pgp pub - image/gif gif - image/jpeg jpeg jpg - image/png png - image/svg+xml svg - application/xml xml rss +{% for type in httpd_supported_types %} + {{ type }} +{% endfor %} } -{% if inventory_hostname == __global_domain_controller %} -server "default" { +server "acme" { listen on localhost port 8888 location "/.well-known/acme-challenge/*" { @@ -24,8 +18,7 @@ server "default" { block return 302 "https://$HTTP_HOST$REQUEST_URI" } } -{% endif %} -{% for file in configuration_files.files %} +{% for file in httpd_configuration_files.files %} include "{{ file.path }}" {% endfor %} diff --git a/roles/httpd_pre/defaults/main.yml b/roles/httpd_pre/defaults/main.yml deleted file mode 100644 index 3b0acd0..0000000 --- a/roles/httpd_pre/defaults/main.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- - -httpd_configuration_file: /etc/httpd.conf -httpd_configuration_dir: /etc/httpd.d -httpd_chroot: /var/www - -httpd_user: www -httpd_group: www diff --git a/roles/httpd_pre/tasks/main.yml b/roles/httpd_pre/tasks/main.yml deleted file mode 100644 index acc6673..0000000 --- a/roles/httpd_pre/tasks/main.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- - -- name: create httpd directory - ansible.builtin.file: - path: /etc/httpd.d - state: directory - owner: 0 - group: 0 - mode: "0644" - -- name: create htpasswd directory - ansible.builtin.file: - path: /var/www/htpasswd - state: directory - owner: "www" - group: "www" - mode: "0700" - -- name: mount nfs in chroot - ansible.builtin.include_role: - name: nfsclient - vars: - nfsclient_dir: "{{ httpd_chroot }}/data" - when: httpd_use_nfs diff --git a/roles/httpd_site_healthcheck/defaults/main.yml b/roles/httpd_site_healthcheck/defaults/main.yml deleted file mode 100644 index 3b0acd0..0000000 --- a/roles/httpd_site_healthcheck/defaults/main.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- - -httpd_configuration_file: /etc/httpd.conf -httpd_configuration_dir: /etc/httpd.d -httpd_chroot: /var/www - -httpd_user: www -httpd_group: www diff --git a/roles/httpd_site_healthcheck/meta/main.yml b/roles/httpd_site_healthcheck/meta/main.yml deleted file mode 100644 index dd93239..0000000 --- a/roles/httpd_site_healthcheck/meta/main.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- - -dependencies: - - role: httpd_pre - tags: dependency diff --git a/roles/httpd_site_healthcheck/tasks/main.yml b/roles/httpd_site_healthcheck/tasks/main.yml deleted file mode 100644 index 7cb2edb..0000000 --- a/roles/httpd_site_healthcheck/tasks/main.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- - -- name: create httpd healthcheck directory - ansible.builtin.file: - path: "{{ httpd_chroot }}/htdocs/healthcheck" - owner: "{{ httpd_user }}" - group: "{{ httpd_group }}" - mode: "0550" - state: directory - -- name: generate generate httpd healthcheck html index - ansible.builtin.template: - src: index.html.j2 - dest: "{{ httpd_chroot }}/htdocs/healthcheck/index.html" - owner: "{{ httpd_user }}" - group: "{{ httpd_group }}" - mode: "0440" - -- name: generate httpd healthcheck configuration - ansible.builtin.template: - src: httpd.conf.j2 - dest: "{{ httpd_configuration_dir }}/healthcheck.conf" - owner: 0 - group: 0 - mode: "0644" diff --git a/roles/httpd_site_healthcheck/templates/httpd.conf.j2 b/roles/httpd_site_healthcheck/templates/httpd.conf.j2 deleted file mode 100644 index 17ffd04..0000000 --- a/roles/httpd_site_healthcheck/templates/httpd.conf.j2 +++ /dev/null @@ -1,6 +0,0 @@ -# managed by Ansible - -server "healthcheck" { - listen on * port 8000 - root "/htdocs/healthcheck" -} diff --git a/roles/httpd_site_healthcheck/templates/index.html.j2 b/roles/httpd_site_healthcheck/templates/index.html.j2 deleted file mode 100644 index c52ff41..0000000 --- a/roles/httpd_site_healthcheck/templates/index.html.j2 +++ /dev/null @@ -1,34 +0,0 @@ - - - -{{ inventory_hostname }} - healtcheck - - - -

{{ inventory_hostname }} - healtcheck

-
-
Thank you for using {{ inventory_hostname }}.
- - -- cgit v1.2.3