Skip to content

Commit

Permalink
Split CentOS into CentOS-6 and CentOS-7 and lookup the service everyw…
Browse files Browse the repository at this point in the history
…here.
  • Loading branch information
robertdebock committed Oct 10, 2018
1 parent 215138d commit ba8b4a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
6 changes: 4 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# handlers file for firewall
- name: reload firewall
service:
name: "{{ firewall_service[ansible_distribution]
| default[firewall_service['default'] }}"
name: "{{ firewall_service[ansible_distribution ~ '-' ~ ansible_distribution_major_version]
| default(firewall_service[ansible_distribution]
| default(firewall_service['default'])) }}"

state: reloaded
when:
- ansible_virtualization_type != "docker"
32 changes: 21 additions & 11 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
- name: remove conflicting software
package:
name: "{{ firewall_packages['conflicting'][ansible_distribution]
| default(firewall_packages['conflicting']['default']) }}"
| default(firewall_packages['conflicting'][ansible_distribution ~ '-' ~ ansible_distribution_major_version]
| default(firewall_packages['conflicting']['default'])) }}"
state: absent
when:
- firewall_packages.conflicting is defined
Expand All @@ -26,8 +27,10 @@
- "{{ firewall_services }}"
when:
- firewall_services is defined
- firewall_service == "ufw"
- ansible_virtualization_type != "docker"
- firewall_service[ansible_distribution ~ '-' ~ ansible_distribution_major_version]
| default (firewall_service[ansible_distribution]
| default (firewall_service['default'])) == "ufw"
loop_control:
label: "{{ item.name }}"

Expand All @@ -40,7 +43,9 @@
- "{{ firewall_services }}"
when:
- firewall_services is defined
- firewall_service == "firewalld"
- firewall_service[ansible_distribution ~ '-' ~ ansible_distribution_major_version]
| default (firewall_service[ansible_distribution]
| default (firewall_service['default'])) == "firewalld"
- ansible_virtualization_type != "docker"
- item.name is number
loop_control:
Expand All @@ -55,7 +60,9 @@
- "{{ firewall_services }}"
when:
- firewall_services is defined
- firewall_service == "firewalld"
- firewall_service[ansible_distribution ~ '-' ~ ansible_distribution_major_version]
| default (firewall_service[ansible_distribution]
| default (firewall_service['default'])) == "firewalld"
- ansible_virtualization_type != "docker"
- item.name is not number
loop_control:
Expand All @@ -65,8 +72,9 @@
ufw:
state: enabled
when:
- firewall_service[ansible_distribution]
| default(firewall_service['default']) == "ufw"
- firewall_service[ansible_distribution ~ '-' ~ ansible_distribution_major_version]
| default (firewall_service[ansible_distribution]
| default (firewall_service['default'])) == "ufw"
- ansible_virtualization_type != "docker"

- name: configure iptables
Expand All @@ -78,17 +86,19 @@
when:
- ansible_virtualization_type != "docker"
- firewall_services is defined
- firewall_service[ansible_distribution]
| default(firewall_service['default']) == "iptables"
- firewall_service[ansible_distribution ~ '-' ~ ansible_distribution_major_version]
| default (firewall_service[ansible_distribution]
| default (firewall_service['default'])) == "iptables"
loop_control:
label: "{{ item.name }}"
notify:
- reload firewall

- name: start and enable software
- name: start and enable firewall service
service:
name: "{{ firewall_service[ansible_distribution]
| default(firewall_service['default']) }}"
name: "{{ firewall_service[ansible_distribution ~ '-' ~ ansible_distribution_major_version]
| default(firewall_service[ansible_distribution]
| default(firewall_service['default'])) }}"
state: started
enabled: true
when:
Expand Down

0 comments on commit ba8b4a9

Please sign in to comment.