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

Separated oracle linux and ubuntu plays from each other for iptables. #285

Merged
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
43 changes: 43 additions & 0 deletions playbooks/roles/iptables/tasks/el.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
- name: Install iptables services for persistence
vars:
package_name:
- iptables-services
include_role:
name: safe_yum

- name: Start iptables services
ansible.builtin.service:
name: "iptables"
enabled: true
state: started

- name: Setup iptables chains and rules for billing
become: true
block:
# Ansible 2.9 doesn't allow for chain management so we need to create the chain ourselves
- name: Create user-defined chain
shell: iptables -N USER_TRAFFIC
ignore_errors: true

- name: Insert USER_TRAFFIC chain to OUTPUT
ansible.builtin.iptables:
chain: OUTPUT
jump: USER_TRAFFIC
action: insert

- name: Append rule to USER_TRAFFIC chain
ansible.builtin.iptables:
table: filter
chain: USER_TRAFFIC
destination: 172.16.0.0/21
jump: RETURN
action: append

# Save the rules
- name: Save iptables rules
shell: iptables-save | tee /etc/sysconfig/iptables

- name: Save ip6tables rules
shell: ip6tables-save | tee /etc/sysconfig/ip6tables
when: billing | default(false) | bool
46 changes: 4 additions & 42 deletions playbooks/roles/iptables/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,5 @@
---
- name: Install iptables services for persistence
vars:
package_name:
- iptables-services
include_role:
name: safe_yum
- include_tasks: el.yml
when: ansible_os_family == 'RedHat'

- name: Start iptables services
ansible.builtin.service:
name: "iptables"
enabled: true
state: started

- name: Setup iptables chains and rules for billing
become: true
block:
# Ansible 2.9 doesn't allow for chain management so we need to create the chain ourselves
- name: Create user-defined chain
shell: iptables -N USER_TRAFFIC
ignore_errors: true

- name: Insert USER_TRAFFIC chain to OUTPUT
ansible.builtin.iptables:
chain: OUTPUT
jump: USER_TRAFFIC
action: insert

- name: Append rule to USER_TRAFFIC chain
ansible.builtin.iptables:
table: filter
chain: USER_TRAFFIC
destination: 172.16.0.0/21
jump: RETURN
action: append

# Save the rules
- name: Save iptables rules
shell: iptables-save | tee /etc/sysconfig/iptables

- name: Save ip6tables rules
shell: ip6tables-save | tee /etc/sysconfig/ip6tables
when: billing | default(false) | bool
- include_tasks: ubuntu.yml
when: ansible_distribution == 'Ubuntu'
Empty file.