xoxys.firewalld/tasks/setup.yml

112 lines
3.2 KiB
YAML
Raw Normal View History

2022-06-13 18:47:12 +00:00
---
- block:
- name: Install packages
package:
name: "{{ item }}"
loop:
- firewalld
- python3-firewall
2022-06-13 20:18:21 +00:00
- name: Configure firewalld
template:
src: etc/firewalld/firewalld.conf.j2
dest: /etc/firewalld/firewalld.conf
mode: 0644
notify: __firewalld_reload
2022-06-13 18:47:12 +00:00
- name: Configure firewalld ipsets
template:
src: etc/firewalld/ipsets/ipset.xml.j2
dest: /etc/firewalld/ipsets/{{ item.name }}.xml
2022-06-13 20:18:21 +00:00
mode: 0640
2022-06-13 18:47:12 +00:00
loop: "{{ firewalld_ipsets }}"
loop_control:
label: "{{ item.name }}"
notify: __firewalld_reload
- name: Register active ipsets
find:
paths: /etc/firewalld/ipsets
file_type: file
patterns: "*.xml"
register: __firewalld_ipsets_active
2022-06-13 20:18:21 +00:00
changed_when: False
failed_when: False
2022-06-13 18:47:12 +00:00
- name: Remove unmanaged ipsets
file:
2022-06-13 20:18:21 +00:00
path: "{{ item }}"
2022-06-13 18:47:12 +00:00
state: absent
loop: "{{ __firewalld_ipsets_active.files | map(attribute='path') | list }}"
notify: __firewalld_reload
2022-06-13 20:18:21 +00:00
when: (item | basename | splitext | first) not in (firewalld_ipsets | map(attribute='name') | list)
2022-06-13 18:47:12 +00:00
- name: Configure firewalld services
template:
src: etc/firewalld/services/service.xml.j2
dest: /etc/firewalld/services/{{ item.name }}.xml
2022-06-13 20:18:21 +00:00
mode: 0640
2022-06-13 18:47:12 +00:00
loop: "{{ firewalld_services }}"
loop_control:
label: "{{ item.name }}"
notify: __firewalld_reload
- name: Register active services
find:
paths: /etc/firewalld/services
file_type: file
patterns: "*.xml"
register: __firewalld_services_active
2022-06-13 20:18:21 +00:00
changed_when: False
failed_when: False
2022-06-13 18:47:12 +00:00
- name: Remove unmanaged services
file:
2022-06-13 20:18:21 +00:00
path: "{{ item }}"
2022-06-13 18:47:12 +00:00
state: absent
loop: "{{ __firewalld_services_active.files | map(attribute='path') | list }}"
notify: __firewalld_reload
2022-06-13 20:18:21 +00:00
when: (item | basename | splitext | first) not in (firewalld_services | map(attribute='name') | list)
2022-06-13 18:47:12 +00:00
- name: Configure firewalld zones
template:
src: etc/firewalld/zones/zone.xml.j2
dest: /etc/firewalld/zones/{{ item.name }}.xml
2022-06-13 20:18:21 +00:00
mode: 0640
2022-06-13 18:47:12 +00:00
loop: "{{ firewalld_zones }}"
loop_control:
label: "{{ item.name }}"
notify: __firewalld_reload
- name: Register active zones
find:
paths: /etc/firewalld/zones
file_type: file
patterns: "*.xml"
register: __firewalld_zones_active
2022-06-13 20:18:21 +00:00
changed_when: False
failed_when: False
2022-06-13 18:47:12 +00:00
- name: Remove unmanaged zones
file:
2022-06-13 20:18:21 +00:00
path: "{{ item }}"
2022-06-13 18:47:12 +00:00
state: absent
loop: "{{ __firewalld_zones_active.files | map(attribute='path') | list }}"
notify: __firewalld_reload
2022-06-13 20:18:21 +00:00
when: (item | basename | splitext | first) not in (firewalld_zones | map(attribute='name') | list)
2022-06-13 18:47:12 +00:00
2022-06-19 21:33:05 +00:00
- name: Validate deployed configuration
command: firewall-offline-cmd --check-config
register: __firewalld_check
changed_when: False
failed_when: __firewalld_check.rc != 0
2022-06-13 18:47:12 +00:00
- name: Ensure service is up and running
service:
name: firewalld
daemon_reload: True
enabled: True
state: started
become: True
become_user: root