summaryrefslogtreecommitdiff
path: root/roles/elevate/liquidtruth/tasks/nginx.yml
blob: 2066ce276e7356cb9e853e48376af84e1bf67fff (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
- name: install nginx
  apt:
    name: nginx-light
    state: present

- name: remove nginx default config
  file:
    name: /etc/nginx/sites-enabled/default
    state: absent
  notify: restart nginx

- name: install nginx config snippets
  loop:
    - ssl
    - hsts
  copy:
    src: "{{ global_files_dir }}/common/nginx-snippets/{{ item }}.conf"
    dest: /etc/nginx/snippets/
  notify: restart nginx

- name: generate Diffie-Hellman parameters
  openssl_dhparam:
    path: /etc/ssl/dhparams.pem
    size: 2048
  notify: restart nginx

- name: install nginx config
  template:
    src: nginx.conf.j2
    dest: /etc/nginx/sites-available/liquidtruth
  notify: restart nginx

- name: check if acme certs already exist
  loop: "{{ liquidtruth_hostnames }}"
  stat:
    path: "/var/lib/acme/live/{{ item }}"
  register: acme_cert_stat

- name: set acmecert_missing_hostnames variable
  set_fact:
    acmecert_missing_hostnames: "{{ acme_cert_stat.results | acme_cert_nonexistent(liquidtruth_hostnames) }}"

- name: link nonexistent hostnames to self-signed interim cert
  when: acmecert_missing_hostnames | length > 0
  block:
    - name: get id of existing selfsigned interim certificate
      command: cat /var/lib/acme/.selfsigned-interim-cert
      changed_when: false
      check_mode: false
      register: selfsigned_interim_cert_id

    - name: set selfsigned_interim_cert_id variable
      set_fact:
        selfsigned_interim_cert_id: "{{ selfsigned_interim_cert_id.stdout }}"

    - name: link to snakeoil cert for nonexistent hostnames
      loop: "{{ acmecert_missing_hostnames }}"
      file:
        src: "../certs/{{ selfsigned_interim_cert_id }}"
        dest: "/var/lib/acme/live/{{ item }}"
        state: link

- name: enable vhost config using acme cert
  file:
    src: ../sites-available/liquidtruth
    dest: /etc/nginx/sites-enabled/liquidtruth
    state: link

- name: make sure nginx config has been (re)loaded
  meta: flush_handlers

- name: get certificate using acmetool
  import_role:
    name: acmetool/cert
  vars:
    acmetool_cert_name: "{{ liquidtruth_hostnames[0] }}"
    acmetool_cert_hostnames: "{{ liquidtruth_hostnames }}"