|
| 1 | +--- |
| 2 | +# This playbook can be applied in advance of rolling out a firewall |
| 3 | +# configuration. It sets up a timer that disables the firewalld service after a |
| 4 | +# period of time (default 600s). It should be used as follows: |
| 5 | +# 1. Enable firewalld-watchdog |
| 6 | +# kayobe playbook run etc/kayobe/ansible/firewalld-watchdog.yml -l <hosts> |
| 7 | +# 2. Apply firewall config |
| 8 | +# kayobe <group> host configure -l <hosts> -t network,firewall |
| 9 | +# 3. Disable watchdog |
| 10 | +# kayobe playbook run etc/kayobe/ansible/firewalld-watchdog.yml -l <hosts> -e firewalld_watchdog_state=absent |
| 11 | +# If the firewall changes result in being locked out of the system, the |
| 12 | +# watchdog will disable the firewall after the timeout. |
| 13 | +# Remember to disable the watchdog, otherwise the firewall will be disabled! |
| 14 | + |
| 15 | +- name: Create a systemd timer to stop firewalld |
| 16 | + hosts: seed:seed-hypervisor:overcloud:infra-vms |
| 17 | + tags: |
| 18 | + - firewalld-watchdog |
| 19 | + vars: |
| 20 | + # Watchdog state: present or absent. |
| 21 | + firewalld_watchdog_state: present |
| 22 | + # Watchdog timeout in seconds. |
| 23 | + firewalld_watchdog_timeout_s: 600 |
| 24 | + become: true |
| 25 | + tasks: |
| 26 | + - when: firewalld_watchdog_state == 'present' |
| 27 | + block: |
| 28 | + - name: Create firewalld-watchdog service unit file |
| 29 | + ansible.builtin.copy: |
| 30 | + dest: /etc/systemd/system/firewalld-watchdog.service |
| 31 | + content: | |
| 32 | + [Unit] |
| 33 | + Description=Firewalld watchdog service |
| 34 | +
|
| 35 | + [Service] |
| 36 | + Type=oneshot |
| 37 | + ExecStart=/usr/bin/systemctl stop firewalld |
| 38 | + register: service_result |
| 39 | + |
| 40 | + - name: Create firewalld-watchdog timer unit file |
| 41 | + ansible.builtin.copy: |
| 42 | + dest: /etc/systemd/system/firewalld-watchdog.timer |
| 43 | + content: | |
| 44 | + [Unit] |
| 45 | + Description=Firewalld watchdog timer |
| 46 | +
|
| 47 | + [Timer] |
| 48 | + OnActiveSec={{ firewalld_watchdog_timeout_s }} |
| 49 | + Unit=firewalld-watchdog.service |
| 50 | +
|
| 51 | + [Install] |
| 52 | + WantedBy=timers.target |
| 53 | + register: timer_result |
| 54 | + |
| 55 | + - name: Enable or disable firewalld-watchdog timer |
| 56 | + ansible.builtin.systemd_service: |
| 57 | + name: firewalld-watchdog.timer |
| 58 | + daemon_reload: "{{ service_result is changed or timer_result is changed }}" |
| 59 | + enabled: false |
| 60 | + state: "{{ 'started' if firewalld_watchdog_state == 'present' else 'stopped' }}" |
| 61 | + |
| 62 | + - name: Remove firewalld-watchdog unit files |
| 63 | + ansible.builtin.file: |
| 64 | + path: "/etc/systemd/system/{{ item }}" |
| 65 | + state: absent |
| 66 | + loop: |
| 67 | + - firewalld-watchdog.service |
| 68 | + - firewalld-watchdog.timer |
| 69 | + when: firewalld_watchdog_state == 'absent' |
0 commit comments