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

issue #52 : enable alias by default #54

Merged
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
15 changes: 15 additions & 0 deletions tasks/alias.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# some notes regarding uuid
# see https://github.com/naturalis/ansible-opnsense/issues/61
#
# if the settings of a alias are missing the 'enabled' key, the
# task will set enabled to 1 (as opnsense itself handles a missing enabled tag this way)
#
# opn_alias:
# - uuid: b9ca4f72-ab35-5c48-8460-d71a7ef50184
# settings:
Expand Down Expand Up @@ -72,6 +75,18 @@
label: "{{ item.0.uuid }} {{ item.1.key }}"
when: item.1.list is defined

# issue #52
- name: enable alias by default
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/OPNsense/Firewall/Alias/aliases/alias[@uuid='{{ item.uuid }}']/enabled"
value: "1"
pretty_print: true
with_items:
- "{{ opn_alias | default([]) }}"
when: item.settings | selectattr('key', 'equalto', 'enabled') | length == 0

# valid types can be determined from
# https://github.com/opnsense/core/blob/master/src/opnsense/mvc/app/models/OPNsense/Firewall/Alias.xml
- name: test aliases
Expand Down
30 changes: 30 additions & 0 deletions test/alias-testenable-expect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
<filter>
</filter>
<OPNsense>
<Firewall>
<Alias>
<aliases>
<alias uuid="b9ca4f72-ab35-5c48-8460-d71a7ef50184">
<name>PRIVATE_NETWORKS</name>
<type>network</type>
<description>opn alias PRIVATE_NETWORKS</description>
<content>10.0.0.0/8
172.16.0.0/12
192.168.0.0/16</content>
<enabled>1</enabled>
</alias>
<alias uuid="b948ceaa-1ca9-5009-bad1-04660a926f87">
<name>HTTP_TCP</name>
<type>port</type>
<description>tcp http(s) ports</description>
<content>80
443</content>
<enabled>1</enabled>
</alias>
</aliases>
</Alias>
</Firewall>
</OPNsense>
</opnsense>
13 changes: 13 additions & 0 deletions test/alias-testenable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<opnsense>
<filter>
</filter>
<OPNsense>
<Firewall>
<Alias>
<aliases>
</aliases>
</Alias>
</Firewall>
</OPNsense>
</opnsense>
32 changes: 32 additions & 0 deletions test/alias-testenable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---

opn_alias:
- uuid: b9ca4f72-ab35-5c48-8460-d71a7ef50184
settings:
- key: name
value: PRIVATE_NETWORKS
- key: type
value: network
- key: content
list:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
#- key: enabled
# value: 1
- key: description
value: "opn alias PRIVATE_NETWORKS"
- uuid: b948ceaa-1ca9-5009-bad1-04660a926f87
settings:
- key: name
value: HTTP_TCP
- key: type
value: port
- key: content
list:
- 80
- 443
#- key: enabled
# value: 1
- key: description
value: "tcp http(s) ports"
Loading