aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Gonçalves <me@rgoncalves.se>2021-12-07 15:39:14 +0000
committerRomain Gonçalves <me@rgoncalves.se>2021-12-07 20:24:51 +0000
commit12cf22b1a8d9ad23809ad8048119a6920cbb9675 (patch)
tree9b7e4334497162c2e922e181eb8b01c57fc67e7f
parent333eff6a0aeefcbf573bbf5e725fc27b5b4cb9f6 (diff)
downloadinfrastructure-12cf22b1a8d9ad23809ad8048119a6920cbb9675.tar.gz
roles: Add httpd roles
-rw-r--r--playbooks/site.yml2
-rw-r--r--roles/httpd/defaults/main.yml4
-rw-r--r--roles/httpd/meta/main.yml3
-rw-r--r--roles/httpd/tasks/main.yml19
-rw-r--r--roles/httpd/templates/httpd.conf.j231
-rw-r--r--roles/httpd_pre/tasks/main.yml18
6 files changed, 77 insertions, 0 deletions
diff --git a/playbooks/site.yml b/playbooks/site.yml
index 5030b79..a191eb6 100644
--- a/playbooks/site.yml
+++ b/playbooks/site.yml
@@ -9,3 +9,5 @@
tags: role_nfsd
- role: vmm
tags: role_vmm
+ - role: httpd
+ tags: role_httpd
diff --git a/roles/httpd/defaults/main.yml b/roles/httpd/defaults/main.yml
new file mode 100644
index 0000000..9ccd2f3
--- /dev/null
+++ b/roles/httpd/defaults/main.yml
@@ -0,0 +1,4 @@
+httpd_configuration_file: /etc/httpd.conf
+httpd_configuration_dir: /etc/httpd.d
+httpd_chroot: /var/www
+httpd_use_nfs: false
diff --git a/roles/httpd/meta/main.yml b/roles/httpd/meta/main.yml
new file mode 100644
index 0000000..6b163d1
--- /dev/null
+++ b/roles/httpd/meta/main.yml
@@ -0,0 +1,3 @@
+dependencies:
+ - role: httpd_pre
+ tags: dependency
diff --git a/roles/httpd/tasks/main.yml b/roles/httpd/tasks/main.yml
new file mode 100644
index 0000000..a272afa
--- /dev/null
+++ b/roles/httpd/tasks/main.yml
@@ -0,0 +1,19 @@
+- name: retrieve all configuration files
+ find:
+ path: "{{ httpd_configuration_dir }}"
+ patterns: "*.conf"
+ register: configuration_files
+
+- name: generate httpd configuration
+ template:
+ src: httpd.conf.j2
+ dest: "{{ httpd_configuration_file }}"
+ owner: 0
+ group: 0
+ mode: 0644
+
+- name: enable and restart httpd
+ service:
+ name: httpd
+ state: restarted
+ enabled: true
diff --git a/roles/httpd/templates/httpd.conf.j2 b/roles/httpd/templates/httpd.conf.j2
new file mode 100644
index 0000000..6285d70
--- /dev/null
+++ b/roles/httpd/templates/httpd.conf.j2
@@ -0,0 +1,31 @@
+# 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
+}
+
+{% if inventory_hostname == __global_domain_controller %}
+server "default" {
+ listen on localhost port 8888
+
+ location "/.well-known/acme-challenge/*" {
+ root "/acme"
+ request strip 2
+ }
+
+ location * {
+ block return 302 "https://$HTTP_HOST$REQUEST_URI"
+ }
+}
+{% endif %}
+
+{% for file in configuration_files.files %}
+include "{{ file.path }}"
+{% endfor %}
diff --git a/roles/httpd_pre/tasks/main.yml b/roles/httpd_pre/tasks/main.yml
new file mode 100644
index 0000000..83afb91
--- /dev/null
+++ b/roles/httpd_pre/tasks/main.yml
@@ -0,0 +1,18 @@
+- name: include httpd role variables
+ include_vars: "{{ inventory_dir }}/roles/httpd/defaults/main.yml"
+
+- name: create httpd directory
+ file:
+ path: /etc/httpd.d
+ state: directory
+ owner: 0
+ group: 0
+ mode: 0644
+
+- name: create htpasswd directory
+ file:
+ path: /var/www/htpasswd
+ state: directory
+ owner: "www"
+ group: "www"
+ mode: 0700
remember that computers suck.