aboutsummaryrefslogtreecommitdiffstats
path: root/roles/obsd_ssl/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'roles/obsd_ssl/tasks')
-rw-r--r--roles/obsd_ssl/tasks/main.yml52
1 files changed, 52 insertions, 0 deletions
diff --git a/roles/obsd_ssl/tasks/main.yml b/roles/obsd_ssl/tasks/main.yml
new file mode 100644
index 0000000..ff8cadc
--- /dev/null
+++ b/roles/obsd_ssl/tasks/main.yml
@@ -0,0 +1,52 @@
+- name: Check mandatory variables are defined
+ assert:
+ that:
+ - obsd_ssl_domains is defined
+
+- name: Deploy acme challenge vhost fragment
+ ansible.builtin.template:
+ src: httpd.d/acme.conf
+ dest: "{{ obsd_httpd_conf_d }}/acme.conf"
+ owner: root
+ group: wheel
+ mode: "0644"
+ register: acme_client_vhost_config
+
+- name: Deploy acme-client.conf
+ ansible.builtin.template:
+ src: acme-client.conf.j2
+ dest: /etc/acme-client.conf
+ owner: root
+ group: wheel
+ mode: "0600"
+
+- name: Start httpd
+ ansible.builtin.service:
+ name: httpd
+ state: started
+ when: acme_client_vhost_config is changed # noqa: no-handler
+
+- name: Reload httpd
+ ansible.builtin.service:
+ name: httpd
+ state: reloaded
+ when: acme_client_vhost_config is changed # noqa: no-handler
+
+- name: Generate certificate
+ ansible.builtin.command: acme-client {{ item }}
+ args:
+ creates: "/etc/ssl/{{ item }}.fullchain.pem"
+ loop: "{{ obsd_ssl_domains }}"
+
+- name: Add certificate renewal crontab entry
+ # Implements the example from `man acme-client`
+ # > A cron(8) job can renew the certificate as necessary. On renewal,
+ # > httpd(8) is reloaded:
+ # >
+ # > ~ * * * * acme-client example.com && rcctl reload httpd
+ ansible.builtin.cron:
+ name: "renew {{ item }} certificate"
+ minute: "~"
+ user: root
+ job: "acme-client {{ item }} && rcctl reload httpd"
+ loop: "{{ obsd_ssl_domains }}"