Skip to content

Commit

Permalink
task288 - add dyndns tasks,test,handler (#97)
Browse files Browse the repository at this point in the history
* task288 - add dyndns tasks,test,handler

* add example vars into dyndnstask,add dyndns to test.yml, modified handler and add fake handler

* task288 - makes ansible-lint happy and corrected the dyndns.yml general task

* task288 - fixt test error for dyndns

* requested changes in dyndns.yml, dyndns-test.xml,test.yml
  • Loading branch information
fnateghi authored Sep 13, 2024
1 parent f1492b8 commit 05b1d8c
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 0 deletions.
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
...
77 changes: 77 additions & 0 deletions tasks/dyndns.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
# 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
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>
7 changes: 7 additions & 0 deletions test/dyndns-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
<system>
</system>
<OPNsense>
</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"
4 changes: 4 additions & 0 deletions test/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
- 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
tasks:
- name: include default vars
ansible.builtin.include_vars:
Expand All @@ -44,6 +47,7 @@
- ipsec
- dnsserver
- openvpn
- dyndns
when:
- test | default(_testtask) == _testtask
- ansible.builtin.meta: flush_handlers
Expand Down

0 comments on commit 05b1d8c

Please sign in to comment.