diff options
| author | Joe Carstairs <me@joeac.net> | 2026-07-29 18:28:50 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-07-29 18:28:50 +0100 |
| commit | 2f43ae3d10dcba9bf70f008ef006122b1613f225 (patch) | |
| tree | 2fc941fc30cc848a6be4b1718add5c2cb44037b3 /ansible/roles/tls/tasks | |
| parent | 6f5c91c7c38a2729dfaa20ae309a3f21e43f301b (diff) | |
move tls cert management from make to ansible
Diffstat (limited to 'ansible/roles/tls/tasks')
| -rw-r--r-- | ansible/roles/tls/tasks/main.yml | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ansible/roles/tls/tasks/main.yml b/ansible/roles/tls/tasks/main.yml new file mode 100644 index 0000000..d26435b --- /dev/null +++ b/ansible/roles/tls/tasks/main.yml @@ -0,0 +1,46 @@ +- name: Create Ansible facts directory + ansible.builtin.file: + path: /etc/ansible/facts.d + state: directory + recurse: true + +- name: Install certbot facts script + register: certbot_fact_script + ansible.builtin.copy: + src: certbot.fact + dest: /etc/ansible/facts.d/certbot.fact + mode: "775" + +- name: Re-gather custom facts + when: certbot_fact_script is changed + ansible.builtin.setup: + filter: ansible_local + +- name: Install certbot and nginx + community.general.apk: + name: + - certbot + - nginx + state: present + +- name: Renew all TLS certificates that are near expiry + when: ( ansible_local.certbot.invalid_certificates | length ) > 0 + ansible.builtin.shell: + certbot renew --non-interactive + +- name: Install missing TLS certificates + loop: "{{ subdomains }}" + when: not ( ( item ~ ".joeac.net" ) in ansible_local.certbot.certificates ) + ansible.builtin.shell: + certbot certonly \ + --nginx \ + --cert-name {{ item }}.joeac.net \ + --domain {% if item == "@" %} joeac.net {% else %} {{ item }}.joeac.net {% endif %} \ + --non-interactive + +- name: Install daily crontab to renew TLS certificates + ansible.builtin.cron: + special_time: daily + name: daily crontab to renew all TLS certificates near to expiry + job: + certbot renew --non-interactive |
