Skip to content

Commit

Permalink
added systemd-override to check config before reloading/restarting
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Sep 24, 2023
1 parent 39d052a commit 7f5ab45
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@
name: ['nftables']
state: present

- name: NFTables | Adding systemd-override directory
ansible.builtin.file:
state: directory
path: '/etc/systemd/system/nftables.service.d'
mode: 0755
owner: 'root'
group: 'root'

- name: NFTables | Copying systemd-override
ansible.builtin.template:
src: "templates/etc/systemd/system/nftables.service.d/override.conf.j2"
dest: '/etc/systemd/system/nftables.service.d/override.conf'
mode: 0644
owner: 'root'
group: 'root'
register: nft_svc_override

- name: NFTables | Loading systemd-override
ansible.builtin.systemd:
daemon_reload: true
name: 'nftables.service'
state: restarted
when: nft_svc_override.changed

- name: NFTables | Adding config directory
ansible.builtin.file:
state: directory
Expand Down
1 change: 1 addition & 0 deletions templates/etc/nftables.conf.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/sbin/nft -f

# {{ ansible_managed }}
# ansibleguy.infra_nftables

flush ruleset

Expand Down
3 changes: 3 additions & 0 deletions templates/etc/nftables.d/table.nft.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/sbin/nft -f

# {{ ansible_managed }}
# ansibleguy.infra_nftables

table {{ nft_table.type }} {{ nft_table_name }} {
{% include "_includes/definition_table.j2" %}

Expand Down
15 changes: 15 additions & 0 deletions templates/etc/systemd/system/nftables.service.d/override.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# {{ ansible_managed }}
# ansibleguy.infra_nftables

[Unit]
Documentation=https://github.com/ansibleguy/infra_nftables

[Service]
ExecStartPre=/usr/sbin/nft -cf /etc/nftables.conf

ExecReload=
ExecReload=/usr/sbin/nft -cf /etc/nftables.conf
ExecReload=/usr/sbin/nft -f /etc/nftables.conf

Restart=on-failure
RestartSec=5s

0 comments on commit 7f5ab45

Please sign in to comment.