Handlers

main.yml

Synopsis: Main task.

Import handlers.

[handlers/main.yml]

 1---
 2# handlers for freebsd_postinstall
 3
 4- name: Import adjkerntz.yml
 5  ansible.builtin.import_tasks: adjkerntz.yml
 6- name: Import apcupsd.yml
 7  ansible.builtin.import_tasks: apcupsd.yml
 8- name: Import devfs.yml
 9  ansible.builtin.import_tasks: devfs.yml
10- name: Import dhclient.yml
11  ansible.builtin.import_tasks: dhclient.yml
12- name: Import fstab.yml
13  ansible.builtin.import_tasks: fstab.yml
14- name: Import hostapd.yml
15  ansible.builtin.import_tasks: hostapd.yml
16- name: Import hostname.yml
17  ansible.builtin.import_tasks: hostname.yml
18- name: Import login.yml
19  ansible.builtin.import_tasks: login.yml
20- name: Import messages.yml
21  ansible.builtin.import_tasks: messages.yml
22- name: Import newaliases.yml
23  ansible.builtin.import_tasks: newaliases.yml
24- name: Import nfsd.yml
25  ansible.builtin.import_tasks: nfsd.yml
26- name: Import nfs.yml
27  ansible.builtin.import_tasks: nfs.yml
28- name: Import ntpdate.yml
29  ansible.builtin.import_tasks: ntpdate.yml
30- name: Import ntpd.yml
31  ansible.builtin.import_tasks: ntpd.yml
32- name: Import qemu.yml
33  ansible.builtin.import_tasks: qemu.yml
34- name: Import resolvconf.yml
35  ansible.builtin.import_tasks: resolvconf.yml
36- name: Import smartd.yml
37  ansible.builtin.import_tasks: smartd.yml
38- name: Import snmpd.yml
39  ansible.builtin.import_tasks: snmpd.yml
40- name: Import sshd.yml
41  ansible.builtin.import_tasks: sshd.yml
42- name: Import swap.yml
43  ansible.builtin.import_tasks: swap.yml
44- name: Import sysctl.yml
45  ansible.builtin.import_tasks: sysctl.yml
46- name: Import wpasupplicant.yml
47  ansible.builtin.import_tasks: wpasupplicant.yml
48
49
50# EOF
51...

adjkerntz.yml

Synopsis: Handler adjkerntz.

Description of the handler.

[handlers/adjkerntz.yml]

1---
2# adjkerntz
3# update the local time CMOS clock and kernel machdep.adjkerntz
4# variable when timezone changes occur
5- name: adjust CMOS
6  ansible.builtin.command:
7    cmd: adjkerntz -a

apcupsd.yml

Synopsis: Handler apcupsd.

Description of the handler.

[handlers/apcupsd.yml]

1---
2# apcupsd
3- name: enable and start apcupsd
4  ansible.builtin.service: name="apcupsd" state="started" enabled=true
5- name: disable and stop apcupsd
6  ansible.builtin.service: name="apcupsd" state="stopped" enabled=false
7- name: restart apcupsd
8  ansible.builtin.service: name="apcupsd" state="restarted"
9  when: fp_apcupsd_enabled|bool

devfs.yml

Synopsis: Handler devfs.

Description of the handler.

[handlers/devfs.yml]

 1---
 2# devfs
 3- name: enable and start devfs
 4  ansible.builtin.service: name="devfs" state="started" enabled=true
 5  when: not ansible_check_mode
 6- name: disable and stop devfs
 7  ansible.builtin.service: name="devfs" state="stopped" enabled=false
 8  when: not ansible_check_mode
 9- name: restart devfs
10  ansible.builtin.service: name="devfs" state="restarted"
11  when: fp_devfs_enabled|bool

dhclient.yml

Synopsis: Handler dhclient.

Description of the handler.

[handlers/dhclient.yml]

 1---
 2# dhclient
 3- name: restart dhclient
 4  ansible.builtin.service:
 5    name: dhclient
 6    state: restarted
 7
 8- name: restart dhclient all
 9  ansible.builtin.command:
10    cmd: "/etc/rc.d/dhclient restart {{ item }}"
11  loop: "{{ fp_dhclient_ifn }}"
12
13- name: restart dhclient blocks
14  ansible.builtin.command:
15    cmd: "/etc/rc.d/dhclient restart {{ item }}"
16  loop: "{{ fp_dhclient_conf_changes.results|
17            selectattr('changed')|
18            map(attribute='item.ifn')|
19            unique }}"

fstab.yml

Synopsis: Handler fstab.

Description of the handler.

[handlers/fstab.yml]

1---
2# fstab
3# - name: mount all
4#  command: mount -a
5- name: Meta noop
6  ansible.builtin.meta: noop

hostapd.yml

Synopsis: Handler hostapd.

Description of the handler.

[handlers/hostapd.yml]

 1---
 2# hostapd
 3- name: enable and start hostapd
 4  ansible.builtin.service: name="hostapd" state="started" enabled=true
 5- name: disable and stop hostapd
 6  ansible.builtin.service: name="hostapd" state="stopped" enabled=false
 7- name: restart hostapd
 8  ansible.builtin.service: name="hostapd" state="restarted"
 9  when: fp_hostapd_enabled|bool
10- name: reload hostapd
11  ansible.builtin.service: name="hostapd" state="reloaded"
12  when: fp_hostapd_enabled|bool

hostname.yml

Synopsis: Handler hostname.

Description of the handler.

[handlers/hostname.yml]

1---
2# hostname
3- name: set hostname
4  ansible.builtin.command:
5    cmd: "hostname {{ rc_conf_hostname }}"

login.yml

Synopsis: Handler login.

Description of the handler.

[handlers/login.yml]

1---
2# login.conf
3- name: rebuild login_conf
4  ansible.builtin.command:
5    cmd: "/usr/bin/cap_mkdb /etc/login.conf"

messages.yml

Synopsis: Handler messages.

Description of the handler.

[handlers/messages.yml]

1---
2- name: loader message reboot
3  ansible.builtin.debug:
4    msg: "[MESSAGE] Reboot to activate configuration in /boot/loader.conf"

newaliases.yml

Synopsis: Handler newaliases.

Description of the handler.

[handlers/newaliases.yml]

1---
2# newaliases
3- name: newaliases
4  ansible.builtin.command:
5    cmd: /usr/bin/newaliases

nfsd.yml

Synopsis: Handler nfsd.

Description of the handler.

[handlers/nfsd.yml]

 1---
 2# nfsd
 3- name: enable and start nfs server
 4  ansible.builtin.service: name="nfsd" state="started" enabled=true
 5- name: disable and stop nfs server
 6  ansible.builtin.service: name="nfsd" state="stopped" enabled=false
 7- name: restart nfs server
 8  ansible.builtin.service: name="nfsd" state="restarted"
 9  when: fp_nfsd_enable|bool
10# mountd
11- name: enable and start mountd
12  ansible.builtin.service: name="mountd" state="started" enabled=true
13- name: disable and stop mountd
14  ansible.builtin.service: name="mountd" state="stopped" enabled=false
15- name: reload mountd
16  ansible.builtin.service: name="mountd" state="reloaded"
17  when: fp_mountd_enable|bool
18# rpcbind
19- name: enable and start rpcbind
20  ansible.builtin.service: name="rpcbind" state="started" enabled=true
21- name: disable and stop rpcbind
22  ansible.builtin.service: name="rpcbind" state="stopped" enabled=false
23- name: restart rpcbind
24  ansible.builtin.service: name="rpcbind" state="restarted"
25  when: fp_rpcbind_enable|bool
26# lockd
27- name: enable and start lockd
28  ansible.builtin.service: name="lockd" state="started" enabled=true
29- name: disable and stop lockd
30  ansible.builtin.service: name="lockd" state="stopped" enabled=false
31- name: restart lockd
32  ansible.builtin.service: name="lockd" state="restarted"
33  when: fp_rpc_lockd_enable|bool
34# statd
35- name: enable and start statd
36  ansible.builtin.service: name="statd" state="started" enabled=true
37- name: disable and stop statd
38  ansible.builtin.service: name="statd" state="stopped" enabled=false
39- name: restart statd
40  ansible.builtin.service: name="statd" state="restarted"
41  when: fp_rpc_statd_enable|bool

nfs.yml

Synopsis: Handler nfs.

Description of the handler.

[handlers/nfs.yml]

1---
2# nfs
3- name: enable and start nfs client
4  ansible.builtin.service: name="nfsclient" state="started" enabled=true
5- name: disable and stop nfs client
6  ansible.builtin.service: name="nfsclient" state="stopped" enabled=false
7- name: restart nfs client
8  ansible.builtin.service: name="nfsclient" state="restarted"
9  when: fp_nfs_enable|bool

ntpdate.yml

Synopsis: Handler ntpdate.

Description of the handler.

[handlers/ntpdate.yml]

1---
2# ntpdate
3- name: enable ntpdate
4  ansible.builtin.service: name="ntpdate" enabled=true
5- name: disable ntpdate
6  ansible.builtin.service: name="ntpdate" enabled=false

ntpd.yml

Synopsis: Handler ntpd.

Description of the handler.

[handlers/ntpd.yml]

1---
2# ntpd
3- name: enable and start ntpd
4  ansible.builtin.service: name="ntpd" state="started" enabled=true
5- name: disable and stop ntpd
6  ansible.builtin.service: name="ntpd" state="stopped" enabled=false
7- name: restart ntpd
8  ansible.builtin.service: name="ntpd" state="restarted"
9  when: fp_ntp_enable|bool

qemu.yml

Synopsis: Handler qemu.

Description of the handler.

[handlers/qemu.yml]

 1---
 2# qemu
 3- name: enable and start qemu
 4  ansible.builtin.service: name="{{ fp_qemu_rcvar }}" state="started" enabled=true
 5- name: disable and stop qemu
 6  ansible.builtin.service: name="{{ fp_qemu_rcvar }}" state="stopped" enabled=false
 7- name: restart qemu
 8  ansible.builtin.service: name="{{ fp_qemu_rcvar }}" state="restarted"
 9  when: fp_qemu_enabled|bool
10- name: reload qemu
11  ansible.builtin.service: name="{{ fp_qemu_rcvar }}" state="reloaded"
12  when: fp_qemu_enabled|bool

resolvconf.yml

Synopsis: Handler resolvconf.

Description of the handler.

[handlers/resolvconf.yml]

1---
2# resolvconf
3- name: resolvconf apply
4  ansible.builtin.command:
5    cmd: resolvconf -u

smartd.yml

Synopsis: Handler smartd.

Description of the handler.

[handlers/smartd.yml]

 1---
 2# smartd
 3- name: enable and start smartd
 4  ansible.builtin.service: name="smartd" state="started" enabled=true
 5- name: disable and stop smartd
 6  ansible.builtin.service: name="smartd" state="stopped" enabled=false
 7- name: restart smartd
 8  ansible.builtin.service: name="smartd" state="restarted"
 9  when: fp_smartd_enabled|bool
10- name: reload smartd
11  ansible.builtin.service: name="smartd" state="reloaded"
12  when: fp_smartd_enabled|bool

snmpd.yml

Synopsis: Handler snmpd.

Description of the handler.

[handlers/snmpd.yml]

1---
2# snmpd
3- name: enable and start snmpd
4  ansible.builtin.service: name="snmpd" state="started" enabled=true
5- name: disable and stop snmpd
6  ansible.builtin.service: name="snmpd" state="stopped" enabled=false
7- name: restart snmpd
8  ansible.builtin.service: name="snmpd" state="restarted"
9  when: fp_snmpd_enabled|bool

sshd.yml

Synopsis: Handler sshd.

Description of the handler.

[handlers/sshd.yml]

 1---
 2# sshd
 3- name: enable and start sshd
 4  ansible.builtin.service: name="sshd" state="started" enabled=true
 5- name: disable and stop sshd
 6  ansible.builtin.service: name="sshd" state="stopped" enabled=false
 7- name: restart sshd
 8  ansible.builtin.service: name="sshd" state="restarted"
 9  when: fp_sshd_enable|bool
10- name: reload sshd
11  ansible.builtin.service: name="sshd" state="reloaded"
12  when: fp_sshd_enable|bool

swap.yml

Synopsis: Handler swap.

Description of the handler.

[handlers/swap.yml]

 1---
 2# swap
 3- name: create swap
 4  ansible.builtin.command:
 5    cmd: >
 6      sh -c
 7      'dd if=/dev/zero of={{ fp_swap_file }} bs=1m count={{ fp_swap_size }} &&
 8      chmod 0600 {{ fp_swap_file }}'
 9
10- name: mount swap
11  ansible.builtin.command:
12    cmd: sh -c 'swapon -aL'
13  register: command_result
14  failed_when: "'adding' not in command_result.stdout"
15# NOTE 1: swapon creates /dev/mdXX
16# NOTE 2: Successful mount returns exit code 1
17# FreeBSD 11.1. Ansible 2.5 command_result:
18# RUNNING HANDLER [vbotka.freebsd-postinstall : mount swap] ***
19# fatal: [aaa.bbb.ccc.ddd]: FAILED! => changed=true
20#  cmd: sh -c 'swapon -aL'
21#  delta: '0:00:00.025491'
22#  end: '2018-07-01 05:47:56.905803'
23#  msg: non-zero return code
24#  rc: 1
25#  start: '2018-07-01 05:47:56.880312'
26#  stderr: ''
27#  stderr_lines: []
28#  stdout: 'swapon: adding /dev/md99 as swap device'
29#  stdout_lines: <omitted>
30
31- name: change and mount swap
32  ansible.builtin.command:
33    cmd: >
34      sh -c
35      'swapoff /dev/{{ fp_swap_md }} &&
36      mdconfig -d -u {{ fp_swap_md }} &&
37      dd if=/dev/zero of={{ fp_swap_file }} bs=1m count={{ fp_swap_size }} &&
38      chmod 0600 {{ fp_swap_file }} &&
39      swapon -aL'
40
41- name: umount and delete swap
42  ansible.builtin.command:
43    cmd: >
44      sh -c
45      'swapoff /dev/{{ fp_swap_md }} &&
46      mdconfig -d -u {{ fp_swap_md }} &&
47      rm {{ fp_swap_file }}'

sysctl.yml

Synopsis: Handler sysctl.

Description of the handler.

[handlers/sysctl.yml]

1---
2# sysctl
3- name: reload sysctl
4  ansible.builtin.service: name="sysctl" state="reloaded"

wpasupplicant.yml

Synopsis: Handler wpasupplicant.

Description of the handler.

[handlers/wpasupplicant.yml]

 1---
 2# wpasupplicant
 3- name: restart netif
 4  ansible.builtin.service: name="netif" state="restarted"
 5
 6- name: reconfigure wpa_supplicant
 7  ansible.builtin.shell:
 8    cmd: >
 9      [ -S {{ fp_wpasupplicant_conf_ctrl_interface }}/{{ item.item.dev }} ] &&
10      wpa_cli -p {{ fp_wpasupplicant_conf_ctrl_interface }} -i {{ item.item.dev }} reconfigure  ||
11      exit 0
12  when: item.changed
13  loop: "{{ fp_wpa_supplicant_conf_changes }}"
14# TODO: Wait for OK result. Error: 'RECONFIGURE' command timed out.