2016-09-03 21:43:40 +02:00
|
|
|
# == State: firewalld.ipsets
|
|
|
|
#
|
|
|
|
# This state ensures that /etc/firewalld/ipsets/ exists.
|
|
|
|
#
|
|
|
|
{% from "firewalld/map.jinja" import firewalld with context %}
|
|
|
|
|
2018-08-25 23:27:37 +02:00
|
|
|
# Backward compatibility setting and deprecation notices
|
|
|
|
{% set ipset_manage = false %}
|
|
|
|
{% set ipset_pkg = 'ipset' %}
|
|
|
|
{% set ipset_sets = firewalld.ipsets %}
|
|
|
|
|
|
|
|
{% if firewalld.ipset is mapping %}
|
|
|
|
{% set ipset_manage = firewalld.ipset.manage %}
|
|
|
|
{% set ipset_pkg = firewalld.ipset.pkg %}
|
|
|
|
{% else %}
|
|
|
|
### Manage setting (old firewalld:ipset)
|
|
|
|
firewalld-ipset-deprecated:
|
|
|
|
test.show_notification:
|
|
|
|
- text: |
|
|
|
|
'firewalld:ipset' format has changed and setting it as boolean is deprecated.
|
|
|
|
Set 'firewalld:ipset:manage' instead.
|
|
|
|
See firewalld/pillar.example for more information
|
|
|
|
|
|
|
|
{% set ipset_manage = firewalld.ipset %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
### Package setting (old firewalld:ipsetpackage)
|
|
|
|
{% if firewalld.ipsetpackage is defined %}
|
|
|
|
firewalld-ipsetpackage-deprecated:
|
|
|
|
test.show_notification:
|
|
|
|
- text: |
|
|
|
|
'firewalld:ipsetpackage' is deprecated. Use 'firewalld:ipset:pkg' instead
|
|
|
|
See firewalld/pillar.example for more information
|
|
|
|
|
|
|
|
{% set ipset_pkg = firewalld.ipsetpackage %}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{%- if ipset_manage %}
|
2016-09-03 21:43:40 +02:00
|
|
|
package_ipset:
|
|
|
|
pkg.installed:
|
2018-08-25 23:27:37 +02:00
|
|
|
- name: {{ ipset_pkg }}
|
2016-09-03 21:43:40 +02:00
|
|
|
|
|
|
|
directory_firewalld_ipsets:
|
|
|
|
file.directory: # make sure this is a directory
|
|
|
|
- name: /etc/firewalld/ipsets
|
|
|
|
- user: root
|
|
|
|
- group: root
|
|
|
|
- mode: 750
|
|
|
|
- require:
|
|
|
|
- pkg: package_firewalld # make sure package is installed
|
2017-03-10 20:14:51 +01:00
|
|
|
- require_in:
|
|
|
|
- service: service_firewalld
|
|
|
|
- watch_in:
|
|
|
|
- cmd: reload_firewalld # reload firewalld config
|
2016-09-03 21:43:40 +02:00
|
|
|
|
|
|
|
# == Define: firewalld.ipsets
|
|
|
|
#
|
|
|
|
# This defines a ipset configuration, see firewalld.ipset (5) man page.
|
|
|
|
#
|
2018-08-25 23:27:37 +02:00
|
|
|
{% for k, v in ipset_sets.items() %}
|
|
|
|
{% set z_name = v.name|default(k) %}
|
2016-09-03 21:43:40 +02:00
|
|
|
|
|
|
|
/etc/firewalld/ipsets/{{ z_name }}.xml:
|
|
|
|
file.managed:
|
|
|
|
- name: /etc/firewalld/ipsets/{{ z_name }}.xml
|
|
|
|
- user: root
|
|
|
|
- group: root
|
|
|
|
- mode: 644
|
|
|
|
- source: salt://firewalld/files/ipset.xml
|
|
|
|
- template: jinja
|
|
|
|
- require:
|
|
|
|
- pkg: package_firewalld # make sure package is installed
|
|
|
|
- file: directory_firewalld_ipsets
|
2017-03-10 20:14:51 +01:00
|
|
|
- require_in:
|
|
|
|
- service: service_firewalld
|
|
|
|
- watch_in:
|
|
|
|
- cmd: reload_firewalld # reload firewalld config
|
2016-09-03 21:43:40 +02:00
|
|
|
- context:
|
2018-05-13 22:14:49 +02:00
|
|
|
name: {{ z_name }}
|
|
|
|
ipset: {{ v }}
|
2016-09-03 21:43:40 +02:00
|
|
|
|
2018-08-25 23:27:37 +02:00
|
|
|
{% endfor %}
|
2016-09-03 21:43:40 +02:00
|
|
|
{%- endif %}
|