2017-12-18 08:52:02 +00:00
|
|
|
---
|
2018-11-05 19:15:12 +00:00
|
|
|
- name: Check if password file '{{ mosquitto_password_auth_file }}' exists
|
|
|
|
stat:
|
|
|
|
path: "{{ mosquitto_password_auth_file }}"
|
|
|
|
register: __mosquitto_passwd
|
|
|
|
become: True
|
|
|
|
become_user: root
|
2017-12-18 08:52:02 +00:00
|
|
|
|
2018-11-05 19:15:12 +00:00
|
|
|
- name: Create password file if not exist
|
|
|
|
file:
|
|
|
|
path: "{{ mosquitto_password_auth_file }}"
|
|
|
|
mode: 0600
|
|
|
|
state: touch
|
2018-11-04 23:31:54 +00:00
|
|
|
become: True
|
|
|
|
become_user: root
|
2018-11-05 19:15:12 +00:00
|
|
|
when: not __mosquitto_passwd.stat.exists
|
|
|
|
|
2018-11-05 19:39:18 +00:00
|
|
|
# TODO: ugly workaround, move this to a custom module
|
2018-11-05 19:15:12 +00:00
|
|
|
- name: Add users to password file
|
2018-11-05 19:39:18 +00:00
|
|
|
shell: "mosquitto_passwd -b {{ mosquitto_password_auth_file }} {{ item.key }} {{ item.value.password }}"
|
2018-11-05 19:28:54 +00:00
|
|
|
with_dict: "{{ mosquitto_password_auth_users | default('{}') }}"
|
2018-11-05 19:45:08 +00:00
|
|
|
when: item.value.state == "present"
|
|
|
|
changed_when: False
|
2018-11-05 20:00:03 +00:00
|
|
|
no_log: True
|
2018-11-05 19:39:18 +00:00
|
|
|
become: True
|
|
|
|
become_user: root
|
|
|
|
|
|
|
|
- name: Remove unnecessary users from password file
|
2018-11-05 19:45:08 +00:00
|
|
|
shell: "mosquitto_passwd -D {{ mosquitto_password_auth_file }} {{ item.key }}"
|
2018-11-05 19:39:18 +00:00
|
|
|
with_dict: "{{ mosquitto_password_auth_users | default('{}') }}"
|
2018-11-05 19:45:08 +00:00
|
|
|
when: item.value.state == "absent"
|
|
|
|
changed_when: False
|
2018-11-05 20:00:03 +00:00
|
|
|
no_log: True
|
2018-11-05 19:39:18 +00:00
|
|
|
become: True
|
|
|
|
become_user: root
|