Initial working configuration.

Next step to refactor so its easier to read.
This commit is contained in:
Matt Spencer committed 2026-09-02 23:31:23 +01:00
1 parent 5aac7eebb8
commit 9531b42cdb
8 files changed
+185 -160

No files matched your search

+111 -74
View File
@@ -1,56 +1,101 @@
---
# - import_playbook: reverse-proxy.yaml
- name: Frontend setup
hosts: frontend
vars:
username: matt
#certbot_auto_renew_user: "{{ ansible_user | default(lookup('env', 'USER')) }}"
certbot_auto_renew_user: "root"
certbot_auto_renew_hour: "3"
certbot_auto_renew_minute: "30"
certbot_create_if_missing: true
certbot_admin_email: matthew@thespencers.me.uk
certbot_certs:
- domains:
- "apptabulous.co.uk"
- "www.apptabulous.co.uk"
- "hub.apptabulous.co.uk"
- "watchtower.apptabulous.co.uk"
webroot: "/var/www/html"
- domains:
- "m5p3nc3r.co.uk"
- "www.m5p3nc3r.co.uk"
- "gitea.m5p3nc3r.co.uk"
webroot: "/var/www/html"
certbot_repo: https://github.com/certbot/certbot.git
certbot_version: master
certbot_keep_updated: true
certbot_dir: /opt/certbot
certbot_create_extra_args: ""
docker_add_repo: true
docker_users:
- "{{ username }}"
roles:
- role: geerlingguy.git
become: true
- role: geerlingguy.docker
become: true
- role: geerlingguy.certbot
become: true
tasks:
- name: Override default certbot start/stop jobs
- name: Ensure SELinux configuration is set to enforcing
ansible.posix.selinux:
policy: targeted
state: enforcing
become: true
- name: Allow container runtimes to use NFS shares (virt_use_nfs)
ansible.posix.seboolean:
name: virt_use_nfs
state: true
persistent: true
become: true
- name: Ensure target directories exist
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0700"
loop:
- "{{ certbot_dir }}"
- "{{ certbot_config_dir }}"
- "{{ certbot_config_dir }}/work"
- "{{ certbot_config_dir }}/logs"
- name: Deploy Cloudflare API credentials file
ansible.builtin.copy:
src: letsencrypt
dest: /etc
dest: "{{ certbot_config_dir }}/cloudflare.ini"
content: |
dns_cloudflare_api_token = {{ cloudflare_api_token }}
mode: "0600"
- name: Install Certbot and Cloudflare plugin via Pip inside virtualenv
ansible.builtin.pip:
name:
- certbot
- certbot-dns-cloudflare
virtualenv: "{{ certbot_dir }}"
virtualenv_command: "python3 -m venv" # Forces Ansible to use Python's built-in module
state: present
- name: Generate Certificate Bundle 1 (apptabulous.co.uk)
ansible.builtin.command:
cmd: >
{{ certbot_dir }}/bin/certbot certonly --non-interactive --agree-tos
--config-dir {{ certbot_config_dir }}
--work-dir {{ certbot_config_dir }}/work
--logs-dir {{ certbot_config_dir }}/logs
--email {{ certbot_admin_email }}
--dns-cloudflare
--dns-cloudflare-credentials {{ certbot_config_dir }}/cloudflare.ini
--dns-cloudflare-propagation-seconds 20
-d apptabulous.co.uk
-d www.apptabulous.co.uk
-d hub.apptabulous.co.uk
-d watchtower.apptabulous.co.uk
creates: "{{ certbot_config_dir }}/live/apptabulous.co.uk/fullchain.pem"
- name: Generate Certificate Bundle 2 (m5p3nc3r.co.uk)
ansible.builtin.command:
cmd: >
{{ certbot_dir }}/bin/certbot certonly --non-interactive --agree-tos
--config-dir {{ certbot_config_dir }}
--work-dir {{ certbot_config_dir }}/work
--logs-dir {{ certbot_config_dir }}/logs
--email {{ certbot_admin_email }}
--dns-cloudflare
--dns-cloudflare-credentials {{ certbot_config_dir }}/cloudflare.ini
--dns-cloudflare-propagation-seconds 60
-d m5p3nc3r.co.uk
-d www.m5p3nc3r.co.uk
-d gitea.m5p3nc3r.co.uk
creates: "{{ certbot_config_dir }}/live/m5p3nc3r.co.uk/fullchain.pem"
- name: Setup User-level Cron for automated renewal
ansible.builtin.cron:
name: "User-space Certbot Renewal"
minute: "30"
hour: "3"
job: >
{{ certbot_dir }}/bin/certbot renew --non-interactive
--config-dir {{ certbot_config_dir }}
--work-dir {{ certbot_config_dir }}/work
--logs-dir {{ certbot_config_dir }}/logs
--post-hook "podman unshare restorecon -R {{ certbot_config_dir }}/live {{ certbot_config_dir }}/archive && podman kill --signal HUP reverse_proxy"
- name: Copy reverse proxy configuration to host
become: true
@@ -58,29 +103,36 @@
src: apptabulous/reverseproxy
dest: /etc
- name: Create webservices network
containers.podman.podman_network:
name: webservices
state: present
- name: Ensure /etc/reverseproxy/certs directory exists
become: true
ansible.builtin.file:
path: /etc/reverseproxy/certs
state: directory
owner: "{{ username }}"
group: "{{ username }}"
mode: "0755"
- name: Start reverse proxy container
community.docker.docker_container:
containers.podman.podman_container:
name: reverse_proxy
image: nginx:alpine
restart_policy: always
network: [webservices]
volumes:
- /etc/reverseproxy/nginx.conf:/etc/nginx/nginx.conf
- /etc/reverseproxy/conf.d:/etc/nginx/conf.d
- /etc/reverseproxy/stream.d:/etc/nginx/stream.d
- /etc/letsencrypt:/etc/letsencrypt
- /home/matt/.config/letsencrypt:/etc/letsencrypt:ro,z
ports:
- "80:80"
- "443:443"
- "2222:2222"
state: started
- name: Start docker registry
community.docker.docker_container:
name: registry
image: registry:2
restart_policy: always
ports:
- "5000:5000"
- "8080:80"
- "8443:443"
# No longer streaming ssh - so can remove this
# - "2222:2222"
state: started
- name: Log into ghcf.io registry
@@ -90,10 +142,11 @@
password: "{{ secrets.GITHUB_TOKEN }}"
- name: Start m5p3nc3r website
community.docker.docker_container:
name: website
containers.podman.podman_container:
name: m5p3nc3r
image: ghcr.io/m5p3nc3r/website:main
restart_policy: always
network: [webservices]
volumes:
- /home/matt/public/apps:/app/public/apps
ports:
@@ -103,27 +156,11 @@
state: started
- name: Start Apptabulous website
community.docker.docker_container:
name: apptabulous_website
containers.podman.podman_container:
name: apptabulous
image: ghcr.io/m5p3nc3r/apptabulous_website:main
restart_policy: always
network: [webservices]
ports:
- "3001:3000"
state: started
- name: Start watchtower
community.docker.docker_container:
name: watchtower
image: nickfedor/watchtower
restart_policy: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /home/matt/.docker/config.json:/config.json
command:
- --cleanup
- --http-api-update
- --http-api-token={{ secrets.WATCHTOWER_HTTP_API_TOKEN }}
- --http-api-periodic-polls
ports:
- "8080:8080"
state: started