0x0i.systemd
Ansible Role: Systemd
Ansible Role that installs and sets up Systemd units, which are system components and services managed by the systemd
service manager in Linux.
Supported Platforms:
- Debian
- Redhat (CentOS/Fedora)
- Ubuntu
Requirements
The systemd
tool is standard for most Linux distributions and should be included with most OS installations. Note that systemd
requires Linux kernel version 3.13 or higher, and kernel version 4.2 or higher for unified cgroup hierarchy support.
Role Variables
Variables are organized by three stages of software & machine setup:
- Install
- Config
- Launch
Install
- path: (default:
/etc/systemd/system
)- The directory where systemd unit configuration files are loaded from. Files in
/etc
take priority over those in/run
, which in turn take priority over/usr/lib
.
- The directory where systemd unit configuration files are loaded from. Files in
Example
unit_config:
- name: apache
path: /run/systemd/system
Service:
ExecStart: /usr/sbin/httpd
ExecReload: /usr/sbin/httpd $OPTIONS -k graceful
Install:
WantedBy: multi-user.target
- type: (default:
service
)- Defines the type of systemd unit to configure, like a service, socket, or mount.
Example
unit_config:
- name: apache
type: socket
Socket:
ListenStream: 0.0.0.0:8080
Accept: yes
Install:
WantedBy: sockets.target
Config
Configuration settings are defined in an INI-style config file. Each systemd unit has common sections like Unit
and Install
, plus one specific to the unit type.
Example for Service
unit_config:
- name: example-service
Unit:
Description: Sleepy service
Service:
ExecStart: /usr/bin/sleep infinity
Install:
WantedBy: multi-user.target
Launch
enabled: (default:
no
)- Specifies if the service should start on boot.
state: (default:
stopped
)- Defines the activation state of the unit.
Dependencies
None
Example Playbook
Example using the role with no specific unit configurations:
- hosts: all
roles:
- role: 0x0I.systemd
Example configuring a service, socket, and mount:
- hosts: webservers
roles:
- role: 0x0I.systemd
vars:
unit_config:
- name: "my-service"
Unit:
After: network-online.target
Wants: network-online.target
Requires: my-service.socket
Service:
User: 'web'
Group: 'web'
ExecStart: '/usr/local/bin/my_service $ARGS'
ExecReload: '/bin/kill -s HUP $MAINPID'
Install:
WantedBy: 'multi-user.target'
- name: "my-service"
type: "socket"
Socket:
ListenStream: '0.0.0.0:4321'
Accept: 'true'
Install:
WantedBy: 'sockets.target'
- name: "var-data-my_service"
type: "mount"
path: "/run/systemd/system"
Mount:
What: '/dev/nvme0'
Where: '/var/data/my_service'
Install:
WantedBy: 'multi-user.target'
License
MIT
Author Information
This role was created in 2019 by O1.IO.