1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/iptables_state/tasks/tests/01-tables.yml
quidame 92242d898d
New module: iptables_state (#271)
* restart from last state

* test (sanity) doc fragment placeholder

* test (sanity) remove doc fragment placeholder

* remove internal params from DOCUMENTATION

* update ignore-2.10.txt

* doc: add changelog fragment

* shorten changelog fragment

* Revert "shorten changelog fragment"

This reverts commit f9aea0d1eaefda139fd5b79bd0eb127c09a433fb.

* test with posix/group1

* test with posix/group3

* test with posix/group5

* test with posix/group4

* test with posix/group3

* New modules/action plugins automatically get a changelog entry

* fix: styles

* Revert "remove internal params from DOCUMENTATION"

This reverts commit 7d5fcf4b17e4cd5b0afc08fd1bd3fcef5fcaee26.

* drop neutral/informative/stateless behaviour

* update tasks after changes in module

* use FQCN in EXAMPLES

* add tests to validate error handling about required params

* doc: remove outdated sentence

* do not document internal parameters

* display timeout value in failure message

* remove inapropriate comment

* merge results and clean them up only once

* conditionally remove tmp path

* at least one iteration is required

* remove deprecated code

* move variables declaration to conditional block

* dissociate async and connection timeout

* improve warnings (conditions + values)

* remove ANSIBLE_METADATA (no more needed); fix typo

* update DOCUMENTATION

* Drop field 'version_added' (no more needed).
* Add a note about check_mode support.

* catch early errors before resetting connection and processing the loop

* fix typo

* change posix group (due to xtables locks); add 'version_added' in doc

* update deprecation (replace Ansible 2.12 by community.general 2.0.0)

* bump version_added to 1.0.0

* update ignore-2.11.txt

* ignore errors for 2.9 as for 2.10 & 2.11

* move action plugin to system/ and replace it by a symlink

* remove action-plugin-docs override in tests/sanity/ignore*.txt

* update action plugin docstrings

* bump version_added to 1.1.0
* use lowercase booleans
* extend usage of namespaces to ansible builtin modules
2020-08-15 10:36:07 +02:00

299 lines
7.9 KiB
YAML

---
- name: "ensure our next rule is not there (iptables)"
iptables:
table: nat
chain: INPUT
jump: ACCEPT
state: absent
- name: "get state (table filter)"
iptables_state:
table: filter
state: saved
path: "{{ iptables_saved }}"
register: iptables_state
changed_when: false
check_mode: yes
- name: "assert that results are as expected"
assert:
that:
- "'*filter' in iptables_state.initial_state"
- iptables_state.tables.filter is defined
- iptables_state.tables.nat is undefined
quiet: yes
- name: "get state (table nat)"
iptables_state:
table: nat
state: saved
path: "{{ iptables_saved }}"
register: iptables_state
changed_when: false
check_mode: yes
- name: "assert that results are as expected"
assert:
that:
- "'*nat' in iptables_state.initial_state"
- "'*filter' in iptables_state.initial_state"
- iptables_state.tables.nat is defined
- iptables_state.tables.filter is undefined
quiet: yes
- name: "save state (table filter)"
iptables_state:
path: "{{ iptables_saved }}"
state: saved
table: filter
register: iptables_state
- name: "assert that results are as expected"
assert:
that:
- "'*filter' in iptables_state.initial_state"
- "'*filter' in iptables_state.saved"
- "'*nat' in iptables_state.initial_state"
- "'*nat' not in iptables_state.saved"
- iptables_state.tables.filter is defined
- iptables_state.tables.nat is undefined
quiet: yes
- name: "save state (table nat)"
iptables_state:
path: "{{ iptables_saved }}"
state: saved
table: nat
register: iptables_state
- name: "assert that results are as expected"
assert:
that:
- iptables_state is changed
- "'*nat' in iptables_state.initial_state"
- "'*nat' in iptables_state.saved"
- "'*filter' in iptables_state.initial_state"
- "'*filter' not in iptables_state.saved"
- iptables_state.tables.nat is defined
- iptables_state.tables.filter is undefined
quiet: yes
- name: "save state (any table)"
iptables_state:
path: "{{ iptables_saved }}"
state: saved
register: iptables_state
- name: "assert that results are as expected"
assert:
that:
- iptables_state is changed
- "'*filter' in iptables_state.initial_state"
- "'*filter' in iptables_state.saved"
- "'*nat' in iptables_state.initial_state"
- "'*nat' in iptables_state.saved"
- iptables_state.tables.filter is defined
- iptables_state.tables.nat is defined
quiet: yes
- name: "restore state (table nat, must NOT report a change, no warning)"
iptables_state:
path: "{{ iptables_saved }}"
state: restored
table: nat
register: iptables_state
async: "{{ ansible_timeout }}"
poll: 0
- name: "assert that results are as expected"
assert:
that:
- "'*nat' in iptables_state.initial_state"
- "'*nat' in iptables_state.restored"
- "'*filter' in iptables_state.initial_state"
- "'*filter' not in iptables_state.restored"
- iptables_state.tables.nat is defined
- iptables_state.tables.filter is undefined
- iptables_state is not changed
quiet: yes
- name: "change NAT table (iptables)"
iptables:
table: nat
chain: INPUT
jump: ACCEPT
state: present
- name: "restore state (table nat, must report a change, no warning)"
iptables_state:
path: "{{ iptables_saved }}"
state: restored
table: nat
register: iptables_state
async: "{{ ansible_timeout }}"
poll: 0
- name: "assert that results are as expected"
assert:
that:
- "'*nat' in iptables_state.initial_state"
- "'*nat' in iptables_state.restored"
- "'*filter' in iptables_state.initial_state"
- "'*filter' not in iptables_state.restored"
- iptables_state.tables.nat is defined
- "'-A INPUT -j ACCEPT' in iptables_state.tables.nat"
- "'-A INPUT -j ACCEPT' not in iptables_state.restored"
- iptables_state.tables.filter is undefined
- iptables_state is changed
quiet: yes
- name: "get security, raw and mangle tables states"
iptables_state:
path: "{{ iptables_saved }}"
state: saved
table: "{{ item }}"
loop:
- security
- raw
- mangle
changed_when: false
check_mode: yes
- name: "save state (any table)"
iptables_state:
path: "{{ iptables_saved }}"
state: saved
register: iptables_state
- name: "assert that results are as expected"
assert:
that:
- "'filter' in iptables_state.tables"
- "'*filter' in iptables_state.saved"
- "'mangle' in iptables_state.tables"
- "'*mangle' in iptables_state.saved"
- "'nat' in iptables_state.tables"
- "'*nat' in iptables_state.saved"
- "'raw' in iptables_state.tables"
- "'*raw' in iptables_state.saved"
- "'security' in iptables_state.tables"
- "'*security' in iptables_state.saved"
quiet: yes
- name: "save filter table into a test file"
iptables_state:
path: "{{ iptables_tests }}"
table: filter
state: saved
- name: "add a table header in comments (# *mangle)"
lineinfile:
path: "{{ iptables_tests }}"
line: "# *mangle"
- name: "restore state (table filter, must NOT report a change, no warning)"
iptables_state:
path: "{{ iptables_tests }}"
table: filter
state: restored
register: iptables_state
async: "{{ ansible_timeout }}"
poll: 0
- name: "assert that results are as expected"
assert:
that:
- "'*filter' in iptables_state.initial_state"
- "'*mangle' in iptables_state.initial_state"
- "'*nat' in iptables_state.initial_state"
- "'*raw' in iptables_state.initial_state"
- "'*security' in iptables_state.initial_state"
- "'filter' in iptables_state.tables"
- "'mangle' not in iptables_state.tables"
- "'nat' not in iptables_state.tables"
- "'raw' not in iptables_state.tables"
- "'security' not in iptables_state.tables"
- "'*filter' in iptables_state.restored"
- "'*mangle' not in iptables_state.restored"
- "'*nat' not in iptables_state.restored"
- "'*raw' not in iptables_state.restored"
- "'*security' not in iptables_state.restored"
- iptables_state is not changed
quiet: yes
- name: "restore state (any table, must NOT report a change, no warning)"
iptables_state:
path: "{{ iptables_tests }}"
state: restored
register: iptables_state
async: "{{ ansible_timeout }}"
poll: 0
- name: "assert that results are as expected"
assert:
that:
- "'*filter' in iptables_state.initial_state"
- "'*mangle' in iptables_state.initial_state"
- "'*nat' in iptables_state.initial_state"
- "'*raw' in iptables_state.initial_state"
- "'*security' in iptables_state.initial_state"
- "'filter' in iptables_state.tables"
- "'mangle' in iptables_state.tables"
- "'nat' in iptables_state.tables"
- "'raw' in iptables_state.tables"
- "'security' in iptables_state.tables"
- "'*filter' in iptables_state.restored"
- "'*mangle' in iptables_state.restored"
- "'*nat' in iptables_state.restored"
- "'*raw' in iptables_state.restored"
- "'*security' in iptables_state.restored"
- iptables_state is not changed
quiet: yes
- name: "restore state (table mangle, must fail, no warning)"
iptables_state:
path: "{{ iptables_tests }}"
table: mangle
state: restored
register: iptables_state
async: "{{ ansible_timeout }}"
poll: 0
ignore_errors: yes
- name: "explain expected failure"
assert:
that:
- iptables_state is failed
- "iptables_state.msg == 'Table mangle to restore not defined in {{ iptables_tests }}'"
success_msg: >-
The previous error has been triggered by trying to restore a table
that is missing in the file provided to iptables-restore.
fail_msg: >-
The previous task should have failed due to a missing table (mangle)
in the file to restore iptables state from.