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 2 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
...
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:

Check failure on line 3 in tasks/dyndns.yml

View workflow job for this annotation

GitHub Actions / ansible lint

yaml[comments]

Missing starting space in comment

Check failure on line 3 in tasks/dyndns.yml

View workflow job for this annotation

GitHub Actions / ansible lint

yaml[comments]

Missing starting space in comment
Copy link
Collaborator

Choose a reason for hiding this comment

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

pls fix the lint errors first ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

and the new dyndns-test should work pls

# - key: enabled
# value: "1"
# - key: verbose
# value: "0"
# - key: allowipv6nano

Check failure on line 8 in tasks/dyndns.yml

View workflow job for this annotation

GitHub Actions / ansible lint

yaml[trailing-spaces]

Trailing spaces

Check failure on line 8 in tasks/dyndns.yml

View workflow job for this annotation

GitHub Actions / ansible lint

yaml[trailing-spaces]

Trailing spaces
# value: "0"
# - key: daemon_delay
# value: "300"
# - key: backend
# value: "opnsense"
#opn_dyndns_accounts:

Check failure on line 14 in tasks/dyndns.yml

View workflow job for this annotation

GitHub Actions / ansible lint

yaml[comments]

Missing starting space in comment

Check failure on line 14 in tasks/dyndns.yml

View workflow job for this annotation

GitHub Actions / ansible lint

yaml[comments]

Missing starting space in comment
# - 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"

Check failure on line 48 in tasks/dyndns.yml

View workflow job for this annotation

GitHub Actions / ansible lint

yaml[trailing-spaces]

Trailing spaces

Check failure on line 48 in tasks/dyndns.yml

View workflow job for this annotation

GitHub Actions / ansible lint

yaml[trailing-spaces]

Trailing spaces

- 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
loop: "{{ opn_dyndns_general }}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

and I would prefer to use `with_items' here
as in all other tasks

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_ng is defined
Copy link
Collaborator

Choose a reason for hiding this comment

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

-    - opn_dyndns_accounts_ng is defined
+    - 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
3 changes: 3 additions & 0 deletions test/dyndns-test-expect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
</opnsense>
49 changes: 49 additions & 0 deletions test/dyndns-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
test_name: simple filter test

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