add full configuration
This commit is contained in:
parent
aec87fdc8b
commit
33ada1c876
3 changed files with 65 additions and 29 deletions
|
@ -3,3 +3,12 @@ mosquitto_accounts:
|
|||
- username: user
|
||||
password_hash: '$6$abcde1234=='
|
||||
open_ufw_to_mosquitto: no
|
||||
mosquitto_config:
|
||||
allow_anonymous: false
|
||||
password_file: /etc/mosquitto/passwd
|
||||
log_dest: stdout
|
||||
pid_file: /var/run/mosquitto/mosquitto.pid
|
||||
mosquitto_listeners:
|
||||
- port: 1883
|
||||
address: localhost
|
||||
|
||||
|
|
|
@ -1,31 +1,41 @@
|
|||
---
|
||||
- name: Ensure Mosquitto doesn't allow anonymous access
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/mosquitto/conf.d/default.conf
|
||||
regexp: '^allow_anonymous '
|
||||
line: 'allow_anonymous false'
|
||||
- name: Configure Mosquitto
|
||||
template:
|
||||
dest: /etc/mosquitto/conf.d/default.conf
|
||||
src: templates/default.conf.j2
|
||||
owner: mosquitto
|
||||
group: root
|
||||
mode: 0660
|
||||
create: yes
|
||||
backup: yes
|
||||
notify: Restart Mosquitto
|
||||
|
||||
- name: Ensure Mosquitto log to standard output (journald)
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/mosquitto/conf.d/default.conf
|
||||
regexp: '^log_dest stdout'
|
||||
line: 'log_dest stdout'
|
||||
owner: mosquitto
|
||||
group: root
|
||||
mode: 0660
|
||||
create: yes
|
||||
backup: yes
|
||||
notify: Restart Mosquitto
|
||||
# - name: Ensure Mosquitto doesn't allow anonymous access
|
||||
# ansible.builtin.lineinfile:
|
||||
# path: /etc/mosquitto/conf.d/default.conf
|
||||
# regexp: '^allow_anonymous '
|
||||
# line: 'allow_anonymous false'
|
||||
# owner: mosquitto
|
||||
# group: root
|
||||
# mode: 0660
|
||||
# create: yes
|
||||
# backup: yes
|
||||
# notify: Restart Mosquitto
|
||||
|
||||
# - name: Ensure Mosquitto log to standard output (journald)
|
||||
# ansible.builtin.lineinfile:
|
||||
# path: /etc/mosquitto/conf.d/default.conf
|
||||
# regexp: '^log_dest stdout'
|
||||
# line: 'log_dest stdout'
|
||||
# owner: mosquitto
|
||||
# group: root
|
||||
# mode: 0660
|
||||
# create: yes
|
||||
# backup: yes
|
||||
# notify: Restart Mosquitto
|
||||
|
||||
- name: Ensure password file for Mosquitto exists
|
||||
template:
|
||||
dest: /etc/mosquitto/passwd
|
||||
dest: "{{ mosquitto_config['password_file'] | default('/etc/mosquitto/passwd')}}"
|
||||
src: templates/mosquitto_passwd.j2
|
||||
owner: mosquitto
|
||||
group: root
|
||||
|
@ -33,20 +43,30 @@
|
|||
backup: yes
|
||||
notify: Restart Mosquitto
|
||||
|
||||
- name: Ensure Mosquitto use password file
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/mosquitto/conf.d/default.conf
|
||||
regexp: '^password_file '
|
||||
line: 'password_file /etc/mosquitto/passwd'
|
||||
- name: Ensure PID file for Mosquitto exists
|
||||
file:
|
||||
path: "{{ mosquitto_config['pid_file'] | default('/var/run/mosquitto.pid')}}"
|
||||
state: touch
|
||||
owner: mosquitto
|
||||
group: root
|
||||
mode: 0660
|
||||
create: yes
|
||||
backup: yes
|
||||
notify: Restart Mosquitto
|
||||
|
||||
# - name: Ensure Mosquitto use password file
|
||||
# ansible.builtin.lineinfile:
|
||||
# path: /etc/mosquitto/conf.d/default.conf
|
||||
# regexp: '^password_file '
|
||||
# line: 'password_file /etc/mosquitto/passwd'
|
||||
# owner: mosquitto
|
||||
# group: root
|
||||
# mode: 0660
|
||||
# create: yes
|
||||
# backup: yes
|
||||
# notify: Restart Mosquitto
|
||||
|
||||
- name: Ensure Mosquitto port is accessible
|
||||
ufw:
|
||||
rule: allow
|
||||
port: 1883
|
||||
when: open_ufw_to_mosquitto
|
||||
port: "{{ item.port }}"
|
||||
when:
|
||||
- open_ufw_to_mosquitto
|
||||
- item.port != 0
|
||||
loop: "{{ mosquitto_listeners }}"
|
||||
|
|
7
templates/default.conf.j2
Normal file
7
templates/default.conf.j2
Normal file
|
@ -0,0 +1,7 @@
|
|||
{{% for key, value in mosquitto_config.items() %}}
|
||||
{{ key }} {{ value }}
|
||||
{{% endfor %}}
|
||||
|
||||
{{% for listener in mosquitto_listeners %}}
|
||||
listener {{ listener.port }} {{ listener.address }}
|
||||
{{% endfor %}}
|
Loading…
Reference in a new issue