Example 4: Control units

Create a playbook

shell> cat lp.yml
- hosts: test_01
  become: true
  roles:
    - vbotka.linux_postinstall

Create the file host_vars/test_01/lp-systemd.yml (1). Enable the import of the tasks (2). Configure the units (3).

 1shell> cat lp-systemd.yml
 2lp_systemd: true
 3lp_systemd_unit:
 4  - name: zfs-mount
 5    control:
 6      enabled: true
 7      state: started
 8      restart_or_reload: restarted
 9  - name: zfs-share
10    control:
11      enabled: true
12      state: started
13      restart_or_reload: restarted
14  - name: zfs-zed
15    control:
16      enabled: true
17      state: started
18      restart_or_reload: restarted

Run the playbook with the tag -t lp_systemd_unit_control to limit the tasks and control the units only

shell> ansible-playbook lp.yml -t lp_systemd_unit_control

TASK [vbotka.linux_postinstall : systemd: Control units] *********************
changed: [test_01] => (item=zfs-mount.service)
changed: [test_01] => (item=zfs-share.service)
changed: [test_01] => (item=zfs-zed.service)

PLAY RECAP *******************************************************************
test_01: ok=6 changed=1 unreachable=0 failed=0 skipped=6 rescued=0 ignored=0

Display the status of zfs-mount.service

shell> systemctl status zfs-mount.service
 zfs-mount.service - Mount ZFS filesystems
     Loaded: loaded (/lib/systemd/system/zfs-mount.service; enabled; vendor preset: enabled)
     Active: active (exited) since Sun 2020-08-09 23:19:45 CEST; 17min ago
       Docs: man:zfs(8)
    Process: 560998 ExecStart=/sbin/zfs mount -a (code=exited, status=0/SUCCESS)
   Main PID: 560998 (code=exited, status=0/SUCCESS)

Display System V status of zfs-* scripts

shell> service --status-all | grep zfs
[ - ]  zfs-import
[ + ]  zfs-mount
[ + ]  zfs-share
[ + ]  zfs-zed