Debian Codegraph @

test/integration/targets/iptables/tasks/chain_management.yml

raw
1 # test code for the iptables module
2 # (c) 2021, Éloi Rivard <[email protected]>
3
4 # This file is part of Ansible
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18 ---
19 - name: get the state of the iptable rules
20 shell: "{{ iptables_bin }} -L"
21 become: true
22 register: result
23
24 - name: assert the rule is absent
25 assert:
26 that:
27 - result is not failed
28 - '"FOOBAR-CHAIN" not in result.stdout'
29
30 - name: create the foobar chain
31 become: true
32 iptables:
33 chain: FOOBAR-CHAIN
34 chain_management: true
35 state: present
36
37 - name: get the state of the iptable rules after chain is created
38 become: true
39 shell: "{{ iptables_bin }} -L"
40 register: result
41
42 - name: assert the rule is present
43 assert:
44 that:
45 - result is not failed
46 - '"FOOBAR-CHAIN" in result.stdout'
47
48 - name: add rule to foobar chain
49 become: true
50 iptables:
51 chain: FOOBAR-CHAIN
52 source: 0.0.0.0
53 destination: 0.0.0.0
54 jump: DROP
55 comment: "FOOBAR-CHAIN RULE"
56
57 - name: get the state of the iptable rules after rule is added to foobar chain
58 become: true
59 shell: "{{ iptables_bin }} -L"
60 register: result
61
62 - name: assert rule is present in foobar chain
63 assert:
64 that:
65 - result is not failed
66 - '"FOOBAR-CHAIN RULE" in result.stdout'
67
68 - name: flush the foobar chain
69 become: true
70 iptables:
71 chain: FOOBAR-CHAIN
72 flush: true
73
74 - name: delete the foobar chain
75 become: true
76 iptables:
77 chain: FOOBAR-CHAIN
78 chain_management: true
79 state: absent
80
81 - name: get the state of the iptable rules after chain is deleted
82 become: true
83 shell: "{{ iptables_bin }} -L"
84 register: result
85
86 - name: assert the rule is absent
87 assert:
88 that:
89 - result is not failed
90 - '"FOOBAR-CHAIN" not in result.stdout'