-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7215530
commit e76a1a8
Showing
25 changed files
with
420 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
--- | ||
|
||
|
||
NFT_ADD_HC: | ||
min_py3_version: '3.3' # 'ipaddress' builtin | ||
dump_keys: | ||
dns: 'dns' | ||
iplist: 'iplist' | ||
cron_prefix: 'nftables_addon' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Source: https://github.com/superstes/python3-resolver | ||
# Copyright (C) 2023 René Pascal Rath | ||
# License: GNU General Public License v3.0 | ||
|
||
from socket import getaddrinfo, gaierror | ||
from ipaddress import IPv4Address, AddressValueError | ||
|
||
DUMMY_PORT = 80 | ||
|
||
|
||
def _is_ipv4_address(i: str) -> bool: | ||
try: | ||
IPv4Address(i) | ||
return True | ||
|
||
except AddressValueError: | ||
return False | ||
|
||
|
||
def _sorted(data: list) -> list: | ||
data.sort() | ||
return data | ||
|
||
|
||
def resolve(name: str) -> list: | ||
try: | ||
raw = getaddrinfo(name, DUMMY_PORT) | ||
# pylint: disable=R1718 | ||
return _sorted(list(set([r[4][0] for r in raw]))) | ||
|
||
except (gaierror, UnicodeError): | ||
return [] | ||
|
||
|
||
def resolve_ipv4(name: str) -> list: | ||
return _sorted([i for i in resolve(name) if _is_ipv4_address(i)]) | ||
|
||
|
||
def resolve_ipv6(name: str) -> list: | ||
return _sorted([i for i in resolve(name) if not _is_ipv4_address(i)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
|
||
roles: | ||
- src: 'ansibleguy.infra_nftables' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
--- | ||
|
||
- name: Verify | ||
hosts: grp_tester | ||
hosts: all | ||
gather_facts: false | ||
tasks: [] | ||
# - name: Checking if zoneminder web-service is reachable | ||
# ansible.builtin.uri: | ||
# url: 'https://192.168.0.2' | ||
# return_content: yes | ||
# validate_certs: false | ||
# register: page | ||
# failed_when: "'Zoneminder' not in page.content" | ||
tasks: | ||
- name: Checking that config is valid | ||
ansible.builtin.command: "nft -cf {{ item }}" | ||
changed_when: false | ||
loop: | ||
- '/etc/nftables.d/addons/dns.nft' | ||
- '/etc/nftables.d/addons/iplist.nft' | ||
- '/etc/nftables.conf' | ||
|
||
- name: Checking that service survives restart | ||
ansible.builtin.systemd: | ||
name: 'nftables.service' | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ | |
become: true | ||
gather_facts: yes | ||
roles: | ||
- ansibleguy.ROLE | ||
- ansibleguy.addons_nftables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
|
||
- name: NFTables-Addons | DNS | Copying helper-script | ||
ansible.builtin.copy: | ||
src: 'files/usr/lib/nftables/dns_resolver.py' | ||
dest: "{{ NTF_ADD_CONFIG.path.lib }}/dns_resolver.py" | ||
owner: 'root' | ||
group: 'root' | ||
mode: 0750 | ||
|
||
- name: NFTables-Addons | DNS | Copying script | ||
ansible.builtin.template: | ||
src: 'templates/usr/lib/nftables/dns.py' | ||
dest: "{{ NTF_ADD_CONFIG.path.lib }}/dns.py" | ||
owner: 'root' | ||
group: 'root' | ||
mode: 0750 | ||
|
||
- name: NFTables-Addons | DNS | Timer | ||
ansible.builtin.include_tasks: timer/main.yml | ||
vars: | ||
addon_key: 'dns' | ||
args: | ||
apply: | ||
tags: dns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
|
||
- name: NFTables-Addons | IP-List | Copying script | ||
ansible.builtin.template: | ||
src: 'templates/usr/lib/nftables/iplist.py' | ||
dest: "{{ NTF_ADD_CONFIG.path.lib }}/iplist.py" | ||
owner: 'root' | ||
group: 'root' | ||
mode: 0750 | ||
|
||
- name: NFTables-Addons | IP-List | Timer | ||
ansible.builtin.include_tasks: timer/main.yml | ||
vars: | ||
addon_key: 'iplist' | ||
args: | ||
apply: | ||
tags: iplist |
Oops, something went wrong.