updated nftables state

This commit is contained in:
Paul 2022-01-02 18:01:47 +01:00
parent b8b5320927
commit 060465a1b1
3 changed files with 21 additions and 2 deletions

15
states/_modules/bl.py Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/python3
import json
from urllib.request import urlopen, Request
def get_ips(url="https://ipbl.paulbsd.com"):
"""get_jobs fetch jobs from dkron"""
fullurl = f"{url}/ips"
req = Request(method="GET", url=fullurl)
res = urlopen(req)
results = json.loads(res.read())
if res.status == 200:
return results
return None

View File

@ -1,2 +1,8 @@
## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }} ## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }}
{% set blackips = salt["bl.get_ips"]() %}
{% if len(blackips) > 0 %}
define blacklist = { {% blackips.join(",") %} }
{% else %}
define blacklist = { 127.255.255.255 } define blacklist = { 127.255.255.255 }
{% endif %}

View File

@ -4,7 +4,6 @@ nftables-config-dir:
file.directory: file.directory:
- name: {{ nftables.config_dir }} - name: {{ nftables.config_dir }}
{%- if not salt['file.file_exists'](nftables.config_dir + "/blacklist.nft") %}
nftables-blacklist-config: nftables-blacklist-config:
file.managed: file.managed:
- name: {{ nftables.config_dir }}/blacklist.nft - name: {{ nftables.config_dir }}/blacklist.nft
@ -15,7 +14,6 @@ nftables-blacklist-config:
- require: - require:
- pkg: nftables-pkg - pkg: nftables-pkg
- file: nftables-config-dir - file: nftables-config-dir
{%- endif %}
nftables-rules-config: nftables-rules-config:
file.managed: file.managed: