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

task288 - add dyndns tasks,test,handler #97

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,11 @@
when:
- config is defined
- config.changed | bool

# dyndns
- name: restart dyndns # noqa no-changed-when
ansible.builtin.command: /usr/local/etc/rc.d/ddclient_opn restart
when:
- config is defined
- config.changed | bool
...
78 changes: 78 additions & 0 deletions tasks/dyndns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
# opn_dyndns_general:
# settings:
# - key: enabled
# value: "1"
# - key: verbose
# value: "0"
# - key: allowipv6
# value: "0"
# - key: daemon_delay
# value: "300"
# - key: backend
# value: "opnsense"
# opn_dyndns_accounts:
# - uuid: "8e4627c4-21ff-4252-a331-3d1adee0a023"
# settings:
# - key: enabled
# value: "1"
# - key: service
# value: "testservice"
# - key: protocol
# value: ""
# - key: server
# value: ""
# - key: username
# value: "user"
# - key: password
# value: "pass"
# - key: resourceId
# value: ""
# - key: hostnames
# value: "all.ddnskey.com"
# - key: wildcard
# value: "0"
# - key: zone
# value: ""
# - key: checkip
# value: "web_noip-ipv4"
# - key: checkip_timeout
# value: "10"
# - key: force_ssl
# value: "1"
# - key: ttl
# value: "300"
# - key: interface
# value: "wan"
# - key: description
# value: "dyndns-description"

- name: DynDNS - Update general DynDNS settings
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/OPNsense/DynDNS/general/{{ item.key }}"
value: "{{ item.value }}"
state: present
pretty_print: true
notify: restart dyndns
with_items:
- "{{ opn_dyndns_general }}"
when:
- opn_dyndns_general is defined

- name: DynDNS - Apply settings for each DynDNS account
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/OPNsense/DynDNS/accounts/account[@uuid='{{ item.0.uuid }}']/{{ item.1.key }}"
value: "{{ item.1.value }}"
state: present
pretty_print: true
notify: restart dyndns
with_subelements:
- "{{ opn_dyndns_accounts }}"
- settings
when:
- opn_dyndns_accounts is defined
- item.1.key != 'enable'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


why do you exclude the enable tag here? how do you handle it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-    - item.1.key != 'enable'

9 changes: 9 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
- dnsserver
- dns

- name: dyndns
tags:
- always
ansible.builtin.include_tasks:
file: dyndns.yml
apply:
tags:
- dyndns

- name: user
tags:
- always
Expand Down
36 changes: 36 additions & 0 deletions test/dyndns-test-expect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
<system>
</system>
<OPNsense>
<DynDNS>
<general>
<enabled>1</enabled>
<verbose>0</verbose>
<allowipv6nano>0</allowipv6nano>
<daemon_delay>300</daemon_delay>
<backend>opnsense</backend>
</general>
<accounts>
<account uuid="8e4627c4-21ff-4252-a331-3d1adee0a023">
<enabled>1</enabled>
<service>noip</service>
<protocol/>
<server/>
<username/>
<password>user</password>
<resourceId>pass</resourceId>
<hostnames>all.ddnskey.com</hostnames>
<wildcard>0</wildcard>
<zone/>
<checkip>web_noip-ipv4</checkip>
<checkip_timeout>10</checkip_timeout>
<force_ssl>1</force_ssl>
<ttl>300</ttl>
<interface>wan</interface>
<description>dyndns-description</description>
</account>
</accounts>
</DynDNS>
</OPNsense>
</opnsense>
36 changes: 36 additions & 0 deletions test/dyndns-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
<system>
</system>
<OPNsense>
zerwes marked this conversation as resolved.
Show resolved Hide resolved
<DynDNS>
<general>
<enabled>1</enabled>
<verbose>0</verbose>
<allowipv6nano>0</allowipv6nano>
<daemon_delay>300</daemon_delay>
<backend>opnsense</backend>
</general>
<accounts>
<account uuid="8e4627c4-21ff-4252-a331-3d1adee0a023">
<enabled>1</enabled>
<service>noip</service>
<protocol/>
<server/>
<username/>
<password>user</password>
<resourceId>pass</resourceId>
<hostnames>all.ddnskey.com</hostnames>
<wildcard>0</wildcard>
<zone/>
<checkip>web_noip-ipv4</checkip>
<checkip_timeout>10</checkip_timeout>
<force_ssl>1</force_ssl>
<ttl>300</ttl>
<interface>wan</interface>
<description>dyndns-description</description>
</account>
</accounts>
</DynDNS>
</OPNsense>
</opnsense>
48 changes: 48 additions & 0 deletions test/dyndns-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---

opn_dyndns_general:
- key: enabled
value: "1"
- key: verbose
value: "0"
- key: allowipv6nano
value: "0"
- key: daemon_delay
value: "300"
- key: backend
value: "opnsense"
opn_dyndns_accounts:
- uuid: "8e4627c4-21ff-4252-a331-3d1adee0a023"
settings:
- key: enabled
value: "1"
- key: service
value: "noip"
- key: protocol
value: ""
- key: server
value: ""
- key: username
value: ""
- key: password
value: "user"
- key: resourceId
value: "pass"
- key: hostnames
value: "all.ddnskey.com"
- key: wildcard
value: "0"
- key: zone
value: ""
- key: checkip
value: "web_noip-ipv4"
- key: checkip_timeout
value: "10"
- key: force_ssl
value: "1"
- key: ttl
value: "300"
- key: interface
value: "wan"
- key: description
value: "dyndns-description"
5 changes: 5 additions & 0 deletions test/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
- name: stop ipsec # TODO: test this action; use community.general.xml and add a tag to the resulting xml
debug:
msg: fake handler - stop ipsec
- name: restart dyndns
debug:
msg: fake handler - restart dyndns

Copy link
Collaborator

@zerwes zerwes Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls, do not add empty lines where there was none was before ...

tasks:
- name: include default vars
ansible.builtin.include_vars:
Expand All @@ -44,6 +48,7 @@
- ipsec
- dnsserver
- openvpn
- dyndns
when:
- test | default(_testtask) == _testtask
- ansible.builtin.meta: flush_handlers
Expand Down
Loading