lab-ansible/roles/vm-common/tasks/firewall.yml
2023-11-12 16:03:21 +01:00

106 lines
2.6 KiB
YAML

# vim: ft=yaml.ansible
# code: language=ansible
---
- name: Move main LAN network to zone 'drop'
ansible.posix.firewalld:
zone: drop
source: 192.168.1.0/24
permanent: true
immediate: true
state: enabled
- name: Move lab network to zone 'dmz'
ansible.posix.firewalld:
zone: dmz
source: 192.168.17.0/24
permanent: true
immediate: true
state: enabled
- name: Move internal network to zone 'internal'
ansible.posix.firewalld:
zone: internal
source: 10.2.0.0/16
permanent: true
immediate: true
state: enabled
when: hostname in groups['virtualservers']
- name: Default deny incoming connections to SSH port in zone 'dmz'
ansible.posix.firewalld:
zone: dmz
service: ssh
permanent: true
immediate: true
state: disabled
- name: Default deny incoming connections to SSH port in zone 'internal'
ansible.posix.firewalld:
zone: internal
service: ssh
permanent: true
immediate: true
state: disabled
when: hostname in groups['virtualservers']
# When sapt-labx-ctl01 is deployed
- name: Allow incoming connections from jump host to SSH port in zone 'dmz'
ansible.posix.firewalld:
zone: dmz
source: "{{ hostvars['sapt-labx-ctl01'].ansible_host }}"
service: ssh
permanent: true
immediate: true
state: enabled
when: false # hostname not in groups['control_infra']
# Until sapt-labx-ctl01 is deployed
- name: Allow incoming connections to SSH port in zone 'drop'
ansible.posix.firewalld:
zone: drop
service: ssh
permanent: true
immediate: true
state: enabled
when: true
- name: Firewall rules for group 'control_infra'
when: hostname in groups['control_infra']
block:
- name: Allow incoming connections to SSH port in zone 'dmz'
ansible.posix.firewalld:
zone: dmz
service: ssh
permanent: true
immediate: true
state: enabled
- name: Allow incoming connections to DNS port in zones 'drop' and 'dmz'
ansible.posix.firewalld:
zone: "{{ item }}"
service: dns
permanent: true
immediate: true
state: enabled
loop:
- drop
- dmz
- name: Firewall rules for production and staging
loop:
- prod
- stage
loop_control:
loop_var: env
block:
- name: Allow incoming connections from app servers to PostgreSQL
ansible.posix.firewalld:
zone: internal
source: "{{ hostvars[item].internal_ipv4 }}"
service: postgresql
permanent: true
immediate: true
state: enabled
loop: "{{ groups['app_' + env] }}"
when: hostname in groups['db_' + env]