diff --git a/states/ipbl/defaults.yaml b/states/ipbl/defaults.yaml new file mode 100644 index 0000000..080a031 --- /dev/null +++ b/states/ipbl/defaults.yaml @@ -0,0 +1,10 @@ +--- +ipbl: + enabled: true + install_dir: /usr/local/apps + release_dir: /usr/local/apps/releases + port: 8099 + mirror: https://git.paulbsd.com/paulbsd/ipbl/releases/download + version: "1.0.0" + os: linux + arch: amd64 diff --git a/states/ipbl/init.sls b/states/ipbl/init.sls new file mode 100644 index 0000000..b71e4b0 --- /dev/null +++ b/states/ipbl/init.sls @@ -0,0 +1,4 @@ +--- +include: + - .install + - .service diff --git a/states/ipbl/install.sls b/states/ipbl/install.sls new file mode 100644 index 0000000..001770c --- /dev/null +++ b/states/ipbl/install.sls @@ -0,0 +1,26 @@ +--- +{%- from "ipbl/map.jinja" import ipbl with context %} +ipbl-archive-extract: + archive.extracted: + - name: {{ ipbl.release_dir }}/ipbl-{{ ipbl.version }} + - source: {{ ipbl.mirror }}/{{ ipbl.version }}/ipbl-{{ ipbl.version }}-{{ ipbl.os }}-{{ ipbl.arch }}.tar.gz + - skip_verify: true + - enforce_toplevel: false + - if_missing: {{ ipbl.release_dir }}/ipbl-{{ ipbl.version }} + - watch_in: + - service: ipbl-service + +ipbl-binary-symlink: + file.symlink: + - name: {{ ipbl.install_dir }}/ipbl + - target: {{ ipbl.release_dir }}/ipbl-{{ ipbl.version }} + - require: + - archive: ipbl-archive-extract + - watch_in: + - service: ipbl-service + +ipbl-cleanup: + software.cleanup: + - name: ipbl + - path: {{ ipbl.release_dir }} + - version: {{ ipbl.version }} diff --git a/states/ipbl/ipbl.service.j2 b/states/ipbl/ipbl.service.j2 new file mode 100644 index 0000000..aa16470 --- /dev/null +++ b/states/ipbl/ipbl.service.j2 @@ -0,0 +1,12 @@ +## {{ salt['pillar.get']('salt_managed', default='Salt Managed') }} +{%- from "ipbl/map.jinja" import ipbl with context %} +[Unit] +Description=ipbl +After=network.target + +[Service] +Type=simple +ExecStart={{ ipbl.install_dir }}/ipbl/ipbl -configfile {{ ipbl.install_dir }}/config/common.ini -port {{ ipbl.port }} + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/states/ipbl/kernelmap.yaml b/states/ipbl/kernelmap.yaml new file mode 100644 index 0000000..40943f2 --- /dev/null +++ b/states/ipbl/kernelmap.yaml @@ -0,0 +1,3 @@ +--- +Linux: + os: "linux" diff --git a/states/ipbl/map.jinja b/states/ipbl/map.jinja new file mode 100644 index 0000000..a50ba8e --- /dev/null +++ b/states/ipbl/map.jinja @@ -0,0 +1,14 @@ +{%- import_yaml "ipbl/defaults.yaml" as default_settings -%} + +{%- import_yaml "ipbl/kernelmap.yaml" as kernelmap -%} +{%- import_yaml "ipbl/osarchmap.yaml" as osarchmap -%} + +{%- set defaults = salt['grains.filter_by'](default_settings, + default='ipbl', + merge=salt['grains.filter_by'](osarchmap, grain='osarch', + merge=salt['grains.filter_by'](kernelmap, grain='kernel') + ) + ) +-%} + +{%- set ipbl = salt['pillar.get']('ipbl', default=defaults, merge=True) -%} \ No newline at end of file diff --git a/states/ipbl/osarchmap.yaml b/states/ipbl/osarchmap.yaml new file mode 100644 index 0000000..4bd82f8 --- /dev/null +++ b/states/ipbl/osarchmap.yaml @@ -0,0 +1,21 @@ +--- +amd64: + arch: "amd64" + +x86_64: + arch: "amd64" + +386: + arch: "386" + +arm64: + arch: "arm64" + +armv6l: + arch: "arm" + +armv7l: + arch: "arm" + +armhf: + arch: "arm" diff --git a/states/ipbl/service.sls b/states/ipbl/service.sls new file mode 100644 index 0000000..bea320c --- /dev/null +++ b/states/ipbl/service.sls @@ -0,0 +1,14 @@ +--- +{%- from "ipbl/map.jinja" import ipbl with context %} +ipbl-service-file: + file.managed: + - name: /etc/systemd/system/ipbl.service + - source: salt://ipbl/ipbl.service.j2 + - user: root + - group: root + - template: jinja + +ipbl-service: + service.running: + - name: ipbl + - enable: true