Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add firewalld/ufw support #722

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion add_balancer.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check failure on line 1 in add_balancer.yml

View workflow job for this annotation

GitHub Actions / build

internal-error

Unexpected error code 1 from execution of: ansible-playbook -i localhost, --syntax-check add_balancer.yml
- name: add_balancer.yml | Add HAProxy balancer node
hosts: balancers
become: true
Expand Down Expand Up @@ -103,7 +103,7 @@
tags: firewall

roles:
- role: ansible-role-firewall
- role: "fw_{{ firewall_type }}"
environment: "{{ proxy_env | default({}) }}"
vars:
firewall_allowed_tcp_ports: "{{ firewall_ports_dynamic_var | default([]) | unique }}"
Expand Down
2 changes: 1 addition & 1 deletion add_pgnode.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check failure on line 1 in add_pgnode.yml

View workflow job for this annotation

GitHub Actions / build

internal-error

Unexpected error code 1 from execution of: ansible-playbook -i localhost, --syntax-check add_pgnode.yml
- name: add_pgnode.yml | PostgreSQL HA Cluster Scaling (add a replica node)
hosts: postgres_cluster
become: true
Expand Down Expand Up @@ -112,7 +112,7 @@
tags: firewall

roles:
- role: ansible-role-firewall
- role: "fw_{{ firewall_type }}"
environment: "{{ proxy_env | default({}) }}"
vars:
firewall_allowed_tcp_ports: "{{ firewall_ports_dynamic_var | default([]) | unique }}"
Expand Down
2 changes: 1 addition & 1 deletion balancers.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check failure on line 1 in balancers.yml

View workflow job for this annotation

GitHub Actions / build

internal-error

Unexpected error code 1 from execution of: ansible-playbook -i localhost, --syntax-check balancers.yml
- name: balancers.yml | Configure HAProxy load balancers
hosts: balancers
become: true
Expand Down Expand Up @@ -76,7 +76,7 @@
tags: firewall

roles:
- role: ansible-role-firewall
- role: "fw_{{ firewall_type }}"
environment: "{{ proxy_env | default({}) }}"
vars:
firewall_allowed_tcp_ports: "{{ firewall_ports_dynamic_var | default([]) | unique }}"
Expand Down
2 changes: 1 addition & 1 deletion config_pgcluster.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check failure on line 1 in config_pgcluster.yml

View workflow job for this annotation

GitHub Actions / build

internal-error

Unexpected error code 1 from execution of: ansible-playbook -i localhost, --syntax-check config_pgcluster.yml
- name: config_pgcluster.yml | Configuration PostgreSQL HA Cluster (based on "Patroni")
hosts: postgres_cluster
gather_facts: true
Expand Down Expand Up @@ -121,7 +121,7 @@
when: dcs_type == "consul" and consul_dnsmasq_enable | bool and ('127.0.0.1' not in (nameservers | default([])))

roles:
- role: ansible-role-firewall
- role: "fw_{{ firewall_type }}"
vars:
firewall_allowed_tcp_ports: "{{ firewall_ports_dynamic_var | default([]) | unique }}"
firewall_additional_rules: "{{ firewall_rules_dynamic_var | default([]) | unique }}"
Expand Down
2 changes: 1 addition & 1 deletion consul.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check failure on line 1 in consul.yml

View workflow job for this annotation

GitHub Actions / build

internal-error

Unexpected error code 1 from execution of: ansible-playbook -i localhost, --syntax-check consul.yml
- name: consul.yml | Configure Consul instances
hosts: consul_instances
become: true
Expand Down Expand Up @@ -132,7 +132,7 @@
when: dcs_type == "consul" and consul_dnsmasq_enable | bool and ('127.0.0.1' in (consul_dnsmasq_servers | default([])))

roles:
- role: ansible-role-firewall
- role: "fw_{{ firewall_type }}"
vars:
firewall_allowed_tcp_ports: "{{ firewall_ports_dynamic_var | default([]) | unique }}"
firewall_additional_rules: "{{ firewall_rules_dynamic_var | default([]) | unique }}"
Expand Down
7 changes: 3 additions & 4 deletions deploy_pgcluster.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

Check failure on line 1 in deploy_pgcluster.yml

View workflow job for this annotation

GitHub Actions / build

internal-error

Unexpected error code 1 from execution of: ansible-playbook -i localhost, --syntax-check deploy_pgcluster.yml

- name: Deploy PostgreSQL HA Cluster (based on "Patroni")
hosts: all
become: true
Expand Down Expand Up @@ -99,7 +98,7 @@
# Ansible requires the iproute package for network facts to be populated
- name: Make sure that the iproute is installed
ansible.builtin.package:
name: iproute
name: "iproute"
state: present
register: package_status
until: package_status is success
Expand All @@ -109,7 +108,7 @@

- name: Make sure that the iproute is installed
ansible.builtin.apt:
name: iproute2
name: "iproute2"
state: present
register: apt_status
until: apt_status is success
Expand Down Expand Up @@ -168,7 +167,7 @@
when: dcs_type == "consul" and consul_dnsmasq_enable | bool and ('127.0.0.1' not in (nameservers | default([])))

roles:
- role: ansible-role-firewall
- role: "fw_{{ firewall_type }}"
environment: "{{ proxy_env | default({}) }}"
vars:
firewall_allowed_tcp_ports: "{{ firewall_ports_dynamic_var | default([]) | unique }}"
Expand Down
2 changes: 1 addition & 1 deletion etcd_cluster.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check failure on line 1 in etcd_cluster.yml

View workflow job for this annotation

GitHub Actions / build

internal-error

Unexpected error code 1 from execution of: ansible-playbook -i localhost, --syntax-check etcd_cluster.yml
- name: etcd_cluster.yml | Deploy etcd Cluster
hosts: etcd_cluster
become: true
Expand Down Expand Up @@ -64,7 +64,7 @@
tags: firewall

roles:
- role: ansible-role-firewall
- role: "fw_{{ firewall_type }}"
environment: "{{ proxy_env | default({}) }}"
vars:
firewall_allowed_tcp_ports: "{{ firewall_ports_dynamic_var | default([]) | unique }}"
Expand Down
6 changes: 6 additions & 0 deletions roles/fw_firewalld/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
firewall_state: started
firewall_enabled_at_boot: true

firewall_allowed_tcp_ports:
- "22"
5 changes: 5 additions & 0 deletions roles/fw_firewalld/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: reload firewalld
ansible.builtin.service:
name: firewalld
state: reloaded
14 changes: 14 additions & 0 deletions roles/fw_firewalld/tasks/disable-other-firewalls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Disable iptables/firewall service.
ansible.builtin.service:
name: firewall
state: stopped
enabled: false
when: ansible_facts.services['firewall.service'] is defined

- name: Disable ufw/firewall service.
ansible.builtin.service:
name: ufw
state: stopped
enabled: false
when: ansible_facts.services['ufw.service'] is defined
30 changes: 30 additions & 0 deletions roles/fw_firewalld/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
- name: Ensure firewalld is present.
ansible.builtin.package:
name: firewalld
state: present
register: package_status
until: package_status is success
delay: 5
retries: 3

- name: Configure the firewalld service.
ansible.builtin.service:
name: firewalld
state: "{{ firewall_state }}"
enabled: "{{ firewall_enabled_at_boot }}"

- name: Configure the firewall service.
ansible.posix.firewalld:
port: "{{ item }}/tcp"
immediate: true
permanent: true
state: enabled
with_items: "{{ firewall_allowed_tcp_ports }}"
notify: reload firewalld

- name: Get services status.
ansible.builtin.service_facts:

- ansible.builtin.import_tasks: disable-other-firewalls.yml
when: ansible_facts.services['firewall.service'] is defined or ansible_facts.services['ufw.service'] is defined
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions roles/fw_ufw/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
firewall_state: started
firewall_enabled_at_boot: true

firewall_allowed_tcp_ports:
- "22"
5 changes: 5 additions & 0 deletions roles/fw_ufw/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: reload ufw
ansible.builtin.service:
name: ufw
state: reloaded
14 changes: 14 additions & 0 deletions roles/fw_ufw/tasks/disable-other-firewalls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Disable iptables/firewall service.
ansible.builtin.service:
name: firewall
state: stopped
enabled: false
when: ansible_facts.services['firewall.service'] is defined

- name: Disable firewalld service.
ansible.builtin.service:
name: firewalld
state: stopped
enabled: false
when: ansible_facts.services['firewalld.service'] is defined
43 changes: 43 additions & 0 deletions roles/fw_ufw/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
- name: Ensure ufw is present.
ansible.builtin.package:
namee: ufw
state: present
register: package_status
until: package_status is success
delay: 5
retries: 3

- name: Enable ufw service
ansible.builtin.service:
name: ufw
state: started
enabled: true

- name: Configure | default (incoming) policy
community.general.ufw:
policy: "deny"
state: enabled
direction: incoming
notify: reload ufw

- name: Configure | default (outgoing) policy
community.general.ufw:
policy: "allow"
state: enabled
direction: outgoing
notify: reload ufw

- name: Configure the ufw service.
community.general.ufw:
rule: allow
port: "{{ item }}"
proto: tcp
with_items: "{{ firewall_allowed_tcp_ports }}"
notify: reload ufw

- name: Get services status.
ansible.builtin.service_facts:

- ansible.builtin.import_tasks: disable-other-firewalls.yml
when: ansible_facts.services['firewall.service'] is defined or ansible_facts.services['firewalld.service'] is defined
3 changes: 2 additions & 1 deletion vars/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ sudo_users:


# Firewall
firewall_enabled_at_boot: false # or 'true' for configure firewall (iptables)
firewall_enabled_at_boot: false # or 'true' for configure firewall
firewall_type: "iptables" # available 'iptables','firewalld','ufw'

firewall_allowed_tcp_ports_for:
master: []
Expand Down
Loading