Skip to content
Snippets Groups Projects
README.md 3.68 KiB
Newer Older
Chris Croome's avatar
Chris Croome committed
# Webarchitects systemd Ansible role
Chris Croome's avatar
Chris Croome committed

Chris Croome's avatar
Chris Croome committed
[![pipeline status](https://git.coop/webarch/systemd/badges/main/pipeline.svg)](https://git.coop/webarch/systemd/-/commits/main)

Chris Croome's avatar
Chris Croome committed
An Ansible role for configuring systemd services on Debian, this role has been designed to be as generic as possible in order to enable to it be used to configure any systemd service.
Chris Croome's avatar
Chris Croome committed

## Role variables

See the [defaults/main.yml](defaults/main.yml) file for the default variables.

### systemd

Set the `systemd` variable to `false` to prevent any tasks in this role being run, it defaults to `true`.

### systemd_timesyncd_reboot

Chris Croome's avatar
Chris Croome committed
When the `systemd_timesyncd_reboot` variable is set to `true` servers which have incorrect clocks will be rebooted by this role in order to correct their clocks, this variable defaults to `false`.
Chris Croome's avatar
Chris Croome committed

### systemd_units

Chris Croome's avatar
Chris Croome committed
A list of systemd units to configure, for example:
Chris Croome's avatar
Chris Croome committed

```yaml
systemd_units:
  - name: systemd-timesyncd
    files:
      - path: /etc/systemd/timesyncd.conf
        comment: |
          Entries in this file show the compile time defaults.
          You can change settings by editing this file.
          Defaults can be restored by simply deleting this file.
          See timesyncd.conf(5) for details.
        conf:
          Time:
            NTP: 0.pool.ntp.org 1.pool.ntp.org 3.pool.ntp.org 2.pool.ntp.org
Chris Croome's avatar
Chris Croome committed
        state: templated
Chris Croome's avatar
Chris Croome committed
    pkgs:
      - systemd-timesyncd
    state: present
    unit_state: started
```

The only required variables is `name`, see the [meta/argument_specs.yml](meta/argument_specs.yml) for the variable types.

Chris Croome's avatar
Chris Croome committed
For each service required `.deb` packages, the state of the service and the files to be created / amended and their content in YAML can be specified.
Chris Croome's avatar
Chris Croome committed

Files are read using the [JC ini parser](https://kellyjonbrazil.github.io/jc/docs/parsers/ini) and only updated if the `conf` is to be changed.

Chris Croome's avatar
Chris Croome committed
Files can optionally have one of three optional states set:
Chris Croome's avatar
Chris Croome committed

Chris Croome's avatar
Chris Croome committed
* `absent` - the file will be deleted.
* `edited` - the existing file will be edited using the [Ansible ini module](https://docs.ansible.com/ansible/latest/collections/community/general/ini_file_module.html).
* `templated` - the file will be created if it does not exist or updated if it already exists using the [templates/unit.j2](templates/unit.j2) template.
Chris Croome's avatar
Chris Croome committed

Chris Croome's avatar
Chris Croome committed
If the `state` is not set it defaults to `templated`.

The `edited` option can not remove variables and, unlike the `templated` option, it preserves existing comments.
Chris Croome's avatar
Chris Croome committed

Chris Croome's avatar
Chris Croome committed
When files are updated or deleted backups are created based on the existing file name but prefixed with a leading `.` and suffixed with a timestamp in ISO8601 format and the file extension `.bak`.

Chris Croome's avatar
Chris Croome committed
## Read existing systemd files using JC
Chris Croome's avatar
Chris Croome committed

You can read existing systemd files as YAML on the command line using [JC](https://github.com/kellyjonbrazil/jc), for example:

```bash
cat /etc/systemd/timesyncd.conf | jc --ini -py
---
Time:
  NTP: 0.pool.ntp.org 1.pool.ntp.org 3.pool.ntp.org 2.pool.ntp.org
```

Chris Croome's avatar
Chris Croome committed
## Dependencies

Chris Croome's avatar
Chris Croome committed
This role requires Ansible 2.11 or newer, [JC](https://pypi.org/project/jc/) and [JMESPath](https://pypi.org/project/jmespath/) to be installed using `pip3` on the Ansible controller.
Chris Croome's avatar
Chris Croome committed

Chris Croome's avatar
Chris Croome committed
## Repository
Chris Croome's avatar
Chris Croome committed

The primary URL of this repo is [`https://git.coop/webarch/systemd`](https://git.coop/webarch/systemd) however it is also [mirrored to GitHub](https://github.com/webarch-coop/ansible-role-systemd) and [available via Ansible Galaxy](https://galaxy.ansible.com/chriscroome/systemd).

If you use this role please use a tagged release, see [the release notes](https://git.coop/webarch/systemd/-/releases).

## License

This role is released under the same terms as Ansible itself, the [GNU GENERAL PUBLIC LICENSE, Version 3](LICENSE).

## Author

Chris Croome's avatar
Chris Croome committed
Copyright [Chris Croome](https://git.coop/chris).