Ansible Role systemd_unit
This role installs and manages systemd unit files. A unit file is a plain text ini-style file that encodes information about a service, a socket, a device, a mount point, an automount point, a swap file or partition, a start-up target, a watched file system path, a timer controlled and supervised by systemd, a resource management slice or a group of externally created processes. See systemd.unit
for unit configuration, systemd.syntax(7)
for a general description of the syntax, and load-fragment-gperf.gperf.in for a list of all directives and their context.
Optional Role Variables
Variable |
Description |
Default Value |
---|---|---|
|
List of Systemd Mount Units. Subkeys:
|
|
|
List of Systemd Service Units. Subkeys:
|
|
|
List of Systemd Timer Units. Subkeys:
|
|
Example:
# optional
systemd_unit__mounts__host_var:
- name: 'mnt-my\x2dfolder'
raw_mount: |-
What=//srv1/my-share
Where=/mnt/my-folder
Type=cifs
Options=credentials=/root/.smbcreds,domain=example.com,vers=default
enabled: true
state: 'started'
# two services, one with more options, one minimal
systemd_unit__services__host_var:
- name: 'fwb'
description: 'Firewall Builder'
raw_unit: |-
After=default.target openvpn-server@server.service fail2ban.service
raw_service: |-
ExecReload=/etc/fwb.sh start
ExecStart=/etc/fwb.sh start
ExecStop=/etc/fwb.sh stop
RemainAfterExit=yes
Type=oneshot
wanted_by: 'basic.target'
state: 'started'
enabled: true
- name: 'duba'
raw_service: |-
ExecStart=/usr/local/bin/duba
Type=oneshot
# two timers, one with more options, one minimal
systemd_unit__timers__host_var:
- name: 'python-venv-update@'
description: 'python-venv update timer for /opt/python-venv/%i'
raw_timer: |-
OnCalendar=daily
Unit=python-venv@%i.service
wanted_by: 'timers.target'
state: 'present'
enabled: true
- name: 'duba'
raw_timer: |-
OnCalendar=daily
# systemd service for a java application
systemd_unit__services__host_var:
- name: 'myjavaapp'
description: 'myjavaapp'
raw_unit: |-
After=syslog.target network.target
Requires=network.target
raw_service: |-
ExecStart=/usr/bin/java -Xmx1g -XX:MaxPermSize=250M -Djava.awt.headless=true -jar /opt/myjavaapp/myjavaapp.jar 8112
Type=simple
User=myjavaapp
WorkingDirectory=/opt/myjavaapp
wanted_by: 'basic.target'
state: 'started'
enabled: true