aboutsummaryrefslogtreecommitdiffstats
path: root/roles/obsd_ssl/tasks/main.yml
blob: 997f35dfa87e3172176b4bf5ba5059958f9d49fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
- 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/ssl.conf
    dest: "{{ obsd_httpd_conf_d }}/ssl.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.name }}
  args:
    creates: "/etc/ssl/{{ item.name }}.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
  # Except I want it once per day rather than once per hour.
  ansible.builtin.cron:
    name: "renew {{ item.name }} certificate"
    minute: "~"
    hour: "~"
    user: root
    job: "acme-client {{ item.name }} && rcctl reload httpd"
  loop: "{{ obsd_ssl_domains }}"