summaryrefslogtreecommitdiff
path: root/roles/x509/static/cert/prepare/tasks/main.yml
blob: 1327c3b3f9b1f29b7b027c34b5aff2739dc8164b (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
79
80
81
---
- name: compute path to static certificate directory
  set_fact:
    static_cert_path: "{{ static_cert_config.path | default([static_cert_base_dir, static_cert_name] | path_join) }}"

- name: create directory for static certificate
  file:
    path: "{{ static_cert_path }}"
    state: directory
    mode: "{{ static_cert_config.mode | default('0700') }}"
    owner: "{{ static_cert_config.owner | default(omit) }}"
    group: "{{ static_cert_config.group | default(omit) }}"
  notify: "{{ x509_notify_on_change | default(omit) }}"

- name: install key for static certificate
  copy:
    content: "{{ static_cert_config.key.content }}"
    dest: "{{ static_cert_path }}/{{ static_cert_name }}-key.pem"
    mode: "{{ static_cert_config.key.mode | default('0600') }}"
    owner: "{{ static_cert_config.key.owner | default(omit) }}"
    group: "{{ static_cert_config.key.group | default(omit) }}"
  notify: "{{ x509_notify_on_change | default(omit) }}"

- name: install static certificate
  copy:
    content: "{{ static_cert_config.cert.content }}"
    dest: "{{ static_cert_path }}/{{ static_cert_name }}-crt.pem"
    mode: "{{ static_cert_config.cert.mode | default('0644') }}"
    owner: "{{ static_cert_config.cert.owner | default(omit) }}"
    group: "{{ static_cert_config.cert.group | default(omit) }}"
  notify: "{{ x509_notify_on_change | default(omit) }}"

- name: export paths to basic certificate files
  set_fact:
    x509_certificate_path_key: "{{ static_cert_path }}/{{ static_cert_name }}-key.pem"
    x509_certificate_path_fullchain: "{{ static_cert_path }}/{{ static_cert_name }}-crt.pem"
    x509_certificate_path_cert: "{{ static_cert_path }}/{{ static_cert_name }}-crt.pem"

- name: install chain and fullchain for static certificate
  when: "'chain' in static_cert_config"
  block:
  - name: install chain for static certificate
    copy:
      content: "{{ static_cert_config.chain.content }}"
      dest: "{{ static_cert_path }}/{{ static_cert_name }}-chain.pem"
      mode: "{{ static_cert_config.chain.mode | default('0644') }}"
      owner: "{{ static_cert_config.chain.owner | default(omit) }}"
      group: "{{ static_cert_config.chain.group | default(omit) }}"
    notify: "{{ x509_notify_on_change | default(omit) }}"

  - name: install fullchain for static certificate
    copy:
      content: |
        {{ static_cert_config.cert.content | trim }}
        {{ static_cert_config.chain.content }}
      dest: "{{ static_cert_path }}/{{ static_cert_name }}-fullchain.pem"
      mode: "{{ static_cert_config.cert.mode | default('0644') }}"
      owner: "{{ static_cert_config.cert.owner | default(omit) }}"
      group: "{{ static_cert_config.cert.group | default(omit) }}"
    notify: "{{ x509_notify_on_change | default(omit) }}"

  - name: export paths to additional certificate files
    set_fact:
      x509_certificate_path_chain: "{{ static_cert_path }}/{{ static_cert_name }}-chain.pem"
      x509_certificate_path_fullchain: "{{ static_cert_path }}/{{ static_cert_name }}-fullchain.pem"

- name: make sure chain and fullchain files are removed
  when: "'chain' not in static_cert_config"
  block:
  - name: remove chain/fullchain files
    loop:
    - chain
    - fullchain
    file:
      path: "{{ static_cert_path }}/{{ static_cert_name }}-{{ item }}.pem"
      state: absent
    notify: "{{ x509_notify_on_change | default(omit) }}"

  - name: make sure variable that points to the chain certificate file is unset
    set_fact:
      x509_certificate_path_chain: ""