From 7fa215a41484d1be11aa99130e8edcaf8209fbd8 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 17 Nov 2023 13:54:56 +0100 Subject: [PATCH] renamed and optimized homepage role --- playbook.yml | 6 ++-- roles/nginx-homepage/Readme.md | 33 +++++++++++++++++++ .../meta/main.yml | 0 .../tasks/main.yml | 6 ++-- .../templates/homepage.nginx.conf.j2 | 0 roles/nginx-homepage/vars/main.yml | 1 + 6 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 roles/nginx-homepage/Readme.md rename roles/{homepage => nginx-homepage}/meta/main.yml (100%) rename roles/{homepage => nginx-homepage}/tasks/main.yml (81%) rename roles/{homepage => nginx-homepage}/templates/homepage.nginx.conf.j2 (100%) create mode 100644 roles/nginx-homepage/vars/main.yml diff --git a/playbook.yml b/playbook.yml index fb1b799f..1df7eba1 100644 --- a/playbook.yml +++ b/playbook.yml @@ -35,11 +35,11 @@ - client-wireguard # Native Webserver Roles -- name: setup homepages - hosts: homepage +- name: setup nginx-homepages + hosts: nginx-homepage become: true roles: - - role: homepage + - role: nginx-homepage vars: domain: "{{top_domain}}" - name: setup redirect hosts diff --git a/roles/nginx-homepage/Readme.md b/roles/nginx-homepage/Readme.md new file mode 100644 index 00000000..7990c05e --- /dev/null +++ b/roles/nginx-homepage/Readme.md @@ -0,0 +1,33 @@ +# Nginx Homepage Role + +This Ansible role configures an Nginx server to serve a static homepage. It handles domain configuration, SSL certificate retrieval with Let's Encrypt, and cloning the homepage content from a Git repository. + +## Requirements + +- Ansible 2.9 or higher +- Nginx installed on the target machine +- Git installed on the target machine (if cloning a repo) +- `https-server` and `git` roles available or configured if they are used as dependencies + +## Role Variables + +- `nginx_homepage_root`: The directory where the homepage content will be stored (default: `/usr/share/nginx/homepage`) +- `domain`: The domain name for the Nginx server configuration +- `administrator_email`: The email used for SSL certificate registration with Let's Encrypt +- `nginx_homepage_repository_address`: The Git repository address containing the homepage content + +## Dependencies + +- `https-server`: A role for setting up an HTTPS server +- `git`: A role for installing Git + +## Example Playbook + +```yaml +- hosts: servers + roles: + - { role: nginx-homepage, domain: 'example.com', administrator_email: 'admin@example.com' } +``` + +## Author Information +This role was created in 2023 by Kevin Veen Birkenbach. \ No newline at end of file diff --git a/roles/homepage/meta/main.yml b/roles/nginx-homepage/meta/main.yml similarity index 100% rename from roles/homepage/meta/main.yml rename to roles/nginx-homepage/meta/main.yml diff --git a/roles/homepage/tasks/main.yml b/roles/nginx-homepage/tasks/main.yml similarity index 81% rename from roles/homepage/tasks/main.yml rename to roles/nginx-homepage/tasks/main.yml index 35987aaa..4d16e19a 100644 --- a/roles/homepage/tasks/main.yml +++ b/roles/nginx-homepage/tasks/main.yml @@ -5,10 +5,10 @@ - name: recieve {{domain}} certificate command: certbot certonly --agree-tos --email {{administrator_email}} --non-interactive --webroot -w /var/lib/letsencrypt/ -d {{domain}} -- name: homepage repo git +- name: nginx-homepage repo git git: - repo: "{{homepage_repository_address}}" - dest: "/usr/share/nginx/homepage" + repo: "{{nginx_homepage_repository_address}}" + dest: "{{nginx_homepage_root}}" update: yes register: git_result ignore_errors: true diff --git a/roles/homepage/templates/homepage.nginx.conf.j2 b/roles/nginx-homepage/templates/homepage.nginx.conf.j2 similarity index 100% rename from roles/homepage/templates/homepage.nginx.conf.j2 rename to roles/nginx-homepage/templates/homepage.nginx.conf.j2 diff --git a/roles/nginx-homepage/vars/main.yml b/roles/nginx-homepage/vars/main.yml new file mode 100644 index 00000000..28595c7c --- /dev/null +++ b/roles/nginx-homepage/vars/main.yml @@ -0,0 +1 @@ +nginx_homepage_root: /usr/share/nginx/homepage \ No newline at end of file