deploy systemd file and create user/group

This commit is contained in:
Robert Kaussow 2017-12-16 22:00:52 +01:00
parent b8fffaa144
commit bbd1314629
3 changed files with 45 additions and 0 deletions

3
defaults/main.yml Normal file
View File

@ -0,0 +1,3 @@
mosquitto_pid_file: /var/run/mosquitto.pid
mosquitto_user: mosquitto
mosquitto_group: mosquitto

View File

@ -14,3 +14,24 @@
with_items:
- mosquitto
- mosquitto-clients
- name: Copy systemd unit files
template:
src: "etc/systemd/system/mosquitto.service.j2"
dest: "/etc/systemd/system/mosquitto.service"
owner: root
group: root
mode: 0644
- name: Create group '{{ mosquitto_group }}'
group:
name: '{{ mosquitto_group }}'
state: present
- name: Create user '{{ mosquitto_user }}'
user:
name: '{{ mosquitto_user }}'
group: '{{ mosquitto_group }}'
system: yes
createhome: no
shell: /sbin/nologin

View File

@ -0,0 +1,21 @@
## {{ ansible_managed }}
[Unit]
Description=Mosquitto MQTT Broker daemon
ConditionPathExists=/etc/mosquitto/mosquitto.conf
After=network.target
Requires=network.target
[Service]
User={{ mosquitto_user }}
Group={{ mosquitto_user }}
Type=forking
RemainAfterExit=no
StartLimitInterval=0
PIDFile={{ mosquitto_pid_file }}
ExecStart=/bin/sh -c "/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf -d"
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=2
[Install]
WantedBy=multi-user.target