Skip to content

Commit

Permalink
simple test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
zerwes committed Dec 5, 2023
1 parent 23b36c9 commit 156c38a
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.*.swp
test/cfg/*.xml
8 changes: 8 additions & 0 deletions test/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[defaults]
inventory = testhosts
gathering = explicit
roles_path = ../../

host_key_checking = False

hash_behaviour = merge
3 changes: 3 additions & 0 deletions test/cfg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### do not delete

in this directory the test cfgs will be placed
22 changes: 22 additions & 0 deletions test/filter-test1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<opnsense>
<filter>
<rule>
<descr>icmp allow</descr>
<type>pass</type>
<ipprotocol>inet</ipprotocol>
<statetype>keep state</statetype>
<direction>any</direction>
<quick>1</quick>
<category>TEST</category>
<floating>yes</floating>
<protocol>icmp</protocol>
<source>
<network>XYZ</network>
</source>
<destination>
<network>ABC</network>
</destination>
</rule>
</filter>
</opnsense>
30 changes: 30 additions & 0 deletions test/filter-test1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---

#local_config_path: cfg/test1.xml

test_name: test consistent setting src/dest to network/address/any ...

opn_filter:
- descr: icmp allow
settings:
- key: type
value: pass
- key: ipprotocol
value: inet
- key: statetype
value: keep state
- key: direction
value: any
- key: quick
value: '1'
- key: category
value: TEST
- key: floating
value: 'yes'
- key: protocol
value: icmp
- key: source/any
value: '1'
- key: destination/any
value: '1'

17 changes: 17 additions & 0 deletions test/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

- name: run test
hosts: testhosts
vars:
config_path: test/{{ inventory_hostname }}.xml
local_config_path: cfg/{{ inventory_hostname }}.xml
tasks:
- name: filter test loop ...
ansible.builtin.include_tasks: testfilter.yml
vars:
_test: "{{ filter_test | basename | splitext | first }}"
with_fileglob:
- "filter-test*.yml"
loop_control:
label: "{{ _test }}"
loop_var: filter_test
21 changes: 21 additions & 0 deletions test/testfilter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

# subtasks for filter test loop

#- name: set test item
# ansible.builtin.set_fact:
# _test: "{{ item | basename | splitext | first }}"
- name: copy test file
ansible.builtin.copy:
src: "{{ _test }}.xml"
dest: "cfg/{{ _test }}.xml"
remote_src: true
- name: read test vars
ansible.builtin.include_vars:
file: "{{ _test }}.yml"
- name: set local cfg path
ansible.builtin.set_fact:
local_config_path: "cfg/{{ _test }}.xml"
- name: import filter task
ansible.builtin.include_tasks:
file: ../tasks/filter.yml
2 changes: 2 additions & 0 deletions test/testhosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[testhosts]
localhost ansible_connection=local

0 comments on commit 156c38a

Please sign in to comment.