summaryrefslogtreecommitdiff
path: root/roles/mosquitto/tasks/main.yml
blob: ed87278909b3caaba7d825784f2df164468032c3 (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
---
- name: install mosquitto
  apt:
    name:
    - mosquitto
    - mosquitto-clients
    state: present

- name: install mosquitto acl files
  loop: "{{ mosquitto_acl_files | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  copy:
    content: |
      # Ansible managed
      {{ item.value }}
    dest: "/etc/mosquitto/{{ item.key }}.acl"
  notify: reload mosquitto

- name: install mosquitto password files
  loop: "{{ mosquitto_password_files | dict2items }}"
  loop_control:
    label: "{{ item.key }}"
  copy:
    content: |
      {{ item.value }}
    dest: "/etc/mosquitto/{{ item.key }}.passwd"
    owner: root
    group: mosquitto
    mode: "0640"
  notify: reload mosquitto

- name: generate Diffie-Hellman parameters
  when: (mosquitto_listeners | dict2items | selectattr('value.tls', 'defined') | length) > 0
  openssl_dhparam:
    path: /etc/mosquitto/certs/dhparams.pem
    size: 2048
  notify: reload mosquitto

- name: generate/install/fetch TLS certificate
  loop: "{{ mosquitto_listeners | dict2items | selectattr('value.tls', 'defined') }}"
  loop_control:
    label: "{{ item.key }}"
  vars:
    x509_certificate_name: "mosquitto-{{ item.key }}"
    x509_certificate_hostnames: "{{ item.value.hostnames }}"
    x509_certificate_config: "{{ item.value.tls.certificate_config | default({}) }}"
    x509_certificate_renewal:
      install:
      - dest: "/etc/mosquitto/certs/{{ item.key }}-crt.pem"
        src:
        - fullchain
        owner: root
        group: mosquitto
        mode: "0644"
      - dest: "/etc/mosquitto/certs/{{ item.key }}-key.pem"
        src:
        - key
        owner: root
        group: mosquitto
        mode: "0640"
    x509_certificate_reload_services:
    - mosquitto
  include_role:
    name: "x509/{{ item.value.tls.certificate_provider }}/cert"

- name: install mosquitto config
  template:
    src: config.j2
    dest: /etc/mosquitto/conf.d/main.conf
  notify: restart mosquitto