From 285dbea53a5cd20239f6e8d5be800a703339cb42 Mon Sep 17 00:00:00 2001 From: Farhad Nateghi <56291706+fnateghi@users.noreply.github.com> Date: Thu, 12 Sep 2024 11:39:46 +0200 Subject: [PATCH 1/5] task288 - add dyndns tasks,test,handler --- handlers/main.yml | 7 ++++ tasks/dyndns.yml | 41 ++++++++++++++++++++ tasks/main.yml | 9 +++++ test/test-dyndn.yml | 72 +++++++++++++++++++++++++++++++++++ test/test-dyndns-expected.xml | 34 +++++++++++++++++ test/test.yml | 4 ++ 6 files changed, 167 insertions(+) create mode 100644 tasks/dyndns.yml create mode 100644 test/test-dyndn.yml create mode 100644 test/test-dyndns-expected.xml diff --git a/handlers/main.yml b/handlers/main.yml index 47da8fb..6813eab 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -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 ... diff --git a/tasks/dyndns.yml b/tasks/dyndns.yml new file mode 100644 index 0000000..fb3a0b7 --- /dev/null +++ b/tasks/dyndns.yml @@ -0,0 +1,41 @@ +--- + +- name: DynDNS - remove DynDNS + delegate_to: localhost + community.general.xml: + path: "{{ local_config_path }}" + xpath: /opnsense/OPNsense/DynDNS{{ item }} + state: absent + pretty_print: true + notify: register dyndns + with_items: "{{ opn_dyndns_accounts_remove }}" + when: opn_dyndns_accouts_remove is defined + +- 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: register dyndns + loop: "{{ 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: register dyndns + with_subelements: + - "{{ opn_dyndns_accounts }}" + - settings + when: + - opn_dyndns_accounts_ng is defined + - item.1.key != 'enable' diff --git a/tasks/main.yml b/tasks/main.yml index f79b3e3..850900d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -25,6 +25,15 @@ - dnsserver - dns +- name: dyndns + tags: + - always + ansible.builtin.include_tasks: + file: dyndns.yml + apply: + tags: + - dyndns + - name: user tags: - always diff --git a/test/test-dyndn.yml b/test/test-dyndn.yml new file mode 100644 index 0000000..4747ba2 --- /dev/null +++ b/test/test-dyndn.yml @@ -0,0 +1,72 @@ +--- +- name: Update DynDNS Configuration XML + hosts: localhost + vars: + opn_dyndns_general: + - 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: "noip" + - key: protocol + value: "" + - key: server + value: "" + - key: username + value: "" + - key: password + value: "" + - 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: "" + tasks: + - name: Update general DynDNS settings + community.general.xml: + path: "{{ playbook_dir }}/dyndns-test-expected.xml" + xpath: "/opnsense/OPNSense/DynDNS/general/{{ item.key }}" + value: "{{ item.value }}" + state: present + pretty_print: true + loop: "{{ opn_dyndns_general }}" + delegate_to: localhost + + - name: Update account specific DynDNS settings + community.general.xml: + path: "{{ playbook_dir }}/dyndns-test-expected.xml" + xpath: "/opnsense/OPNSense/DynDNS/accounts/account[@uuid='{{ item.0.uuid }}']/{{ item.1.key }}" + value: "{{ item.1.value }}" + state: present + pretty_print: true + with_subelements: + - "{{ opn_dyndns_accounts }}" + - settings + delegate_to: localhost diff --git a/test/test-dyndns-expected.xml b/test/test-dyndns-expected.xml new file mode 100644 index 0000000..f3fd03e --- /dev/null +++ b/test/test-dyndns-expected.xml @@ -0,0 +1,34 @@ + + + + + + 1 + 0 + 0 + 300 + opnsense + + + + 1 + noip + + + + + + all.ddnskey.com + 0 + + web_noip-ipv4 + 10 + 1 + 300 + wan + rls-dyndns-noip + + + + + diff --git a/test/test.yml b/test/test.yml index 2e8a39b..128fa79 100644 --- a/test/test.yml +++ b/test/test.yml @@ -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 + tasks: - name: include default vars ansible.builtin.include_vars: From 45c9dacac842cfc3323c77c821a220d4cbfd4745 Mon Sep 17 00:00:00 2001 From: Farhad Nateghi <56291706+fnateghi@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:15:50 +0200 Subject: [PATCH 2/5] add example vars into dyndnstask,add dyndns to test.yml, modified handler and add fake handler --- tasks/dyndns.yml | 62 +++++++++++++++++++++++------- test/dyndns-test-expect.xml | 3 ++ test/dyndns-test.yml | 49 ++++++++++++++++++++++++ test/test-dyndn.yml | 72 ----------------------------------- test/test-dyndns-expected.xml | 34 ----------------- test/test.yml | 1 + 6 files changed, 102 insertions(+), 119 deletions(-) create mode 100644 test/dyndns-test-expect.xml create mode 100644 test/dyndns-test.yml delete mode 100644 test/test-dyndn.yml delete mode 100644 test/test-dyndns-expected.xml diff --git a/tasks/dyndns.yml b/tasks/dyndns.yml index fb3a0b7..1ab57e6 100644 --- a/tasks/dyndns.yml +++ b/tasks/dyndns.yml @@ -1,15 +1,51 @@ --- - -- name: DynDNS - remove DynDNS - delegate_to: localhost - community.general.xml: - path: "{{ local_config_path }}" - xpath: /opnsense/OPNsense/DynDNS{{ item }} - state: absent - pretty_print: true - notify: register dyndns - with_items: "{{ opn_dyndns_accounts_remove }}" - when: opn_dyndns_accouts_remove is defined +# +#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: "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 @@ -19,7 +55,7 @@ value: "{{ item.value }}" state: present pretty_print: true - notify: register dyndns + notify: restart dyndns loop: "{{ opn_dyndns_general }}" when: - opn_dyndns_general is defined @@ -32,7 +68,7 @@ value: "{{ item.1.value }}" state: present pretty_print: true - notify: register dyndns + notify: restart dyndns with_subelements: - "{{ opn_dyndns_accounts }}" - settings diff --git a/test/dyndns-test-expect.xml b/test/dyndns-test-expect.xml new file mode 100644 index 0000000..0cfeed6 --- /dev/null +++ b/test/dyndns-test-expect.xml @@ -0,0 +1,3 @@ + + + diff --git a/test/dyndns-test.yml b/test/dyndns-test.yml new file mode 100644 index 0000000..d5e65c8 --- /dev/null +++ b/test/dyndns-test.yml @@ -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" diff --git a/test/test-dyndn.yml b/test/test-dyndn.yml deleted file mode 100644 index 4747ba2..0000000 --- a/test/test-dyndn.yml +++ /dev/null @@ -1,72 +0,0 @@ ---- -- name: Update DynDNS Configuration XML - hosts: localhost - vars: - opn_dyndns_general: - - 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: "noip" - - key: protocol - value: "" - - key: server - value: "" - - key: username - value: "" - - key: password - value: "" - - 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: "" - tasks: - - name: Update general DynDNS settings - community.general.xml: - path: "{{ playbook_dir }}/dyndns-test-expected.xml" - xpath: "/opnsense/OPNSense/DynDNS/general/{{ item.key }}" - value: "{{ item.value }}" - state: present - pretty_print: true - loop: "{{ opn_dyndns_general }}" - delegate_to: localhost - - - name: Update account specific DynDNS settings - community.general.xml: - path: "{{ playbook_dir }}/dyndns-test-expected.xml" - xpath: "/opnsense/OPNSense/DynDNS/accounts/account[@uuid='{{ item.0.uuid }}']/{{ item.1.key }}" - value: "{{ item.1.value }}" - state: present - pretty_print: true - with_subelements: - - "{{ opn_dyndns_accounts }}" - - settings - delegate_to: localhost diff --git a/test/test-dyndns-expected.xml b/test/test-dyndns-expected.xml deleted file mode 100644 index f3fd03e..0000000 --- a/test/test-dyndns-expected.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - 1 - 0 - 0 - 300 - opnsense - - - - 1 - noip - - - - - - all.ddnskey.com - 0 - - web_noip-ipv4 - 10 - 1 - 300 - wan - rls-dyndns-noip - - - - - diff --git a/test/test.yml b/test/test.yml index 128fa79..3dac9e8 100644 --- a/test/test.yml +++ b/test/test.yml @@ -48,6 +48,7 @@ - ipsec - dnsserver - openvpn + - dyndns when: - test | default(_testtask) == _testtask - ansible.builtin.meta: flush_handlers From d9cc00a88f26c9a4d0e64a332e96611c73178c6c Mon Sep 17 00:00:00 2001 From: Farhad Nateghi <56291706+fnateghi@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:13:12 +0200 Subject: [PATCH 3/5] task288 - makes ansible-lint happy and corrected the dyndns.yml general task --- tasks/dyndns.yml | 33 +++++++++++++++++---------------- test/dyndns-test-expect.xml | 3 --- test/dyndns-test.yml | 21 ++++++++++----------- 3 files changed, 27 insertions(+), 30 deletions(-) delete mode 100644 test/dyndns-test-expect.xml diff --git a/tasks/dyndns.yml b/tasks/dyndns.yml index 1ab57e6..788ff04 100644 --- a/tasks/dyndns.yml +++ b/tasks/dyndns.yml @@ -1,17 +1,17 @@ --- -# -#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: +# 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 @@ -45,7 +45,7 @@ # - key: interface # value: "wan" # - key: description -# value: "dyndns-description" +# value: "dyndns-description" - name: DynDNS - Update general DynDNS settings delegate_to: localhost @@ -56,7 +56,8 @@ state: present pretty_print: true notify: restart dyndns - loop: "{{ opn_dyndns_general }}" + with_items: + - "{{ opn_dyndns_general }}" when: - opn_dyndns_general is defined @@ -73,5 +74,5 @@ - "{{ opn_dyndns_accounts }}" - settings when: - - opn_dyndns_accounts_ng is defined + - opn_dyndns_accounts is defined - item.1.key != 'enable' diff --git a/test/dyndns-test-expect.xml b/test/dyndns-test-expect.xml deleted file mode 100644 index 0cfeed6..0000000 --- a/test/dyndns-test-expect.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/test/dyndns-test.yml b/test/dyndns-test.yml index d5e65c8..51c1735 100644 --- a/test/dyndns-test.yml +++ b/test/dyndns-test.yml @@ -1,17 +1,16 @@ --- -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" + - 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: From a0a00d855e5a1b1d5380bf7613e26b093f3ebda1 Mon Sep 17 00:00:00 2001 From: Farhad Nateghi <56291706+fnateghi@users.noreply.github.com> Date: Thu, 12 Sep 2024 17:21:25 +0200 Subject: [PATCH 4/5] task288 - fixt test error for dyndns --- test/dyndns-test-expect.xml | 36 ++++++++++++++++++++++++++++++++++++ test/dyndns-test.xml | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 test/dyndns-test-expect.xml create mode 100644 test/dyndns-test.xml diff --git a/test/dyndns-test-expect.xml b/test/dyndns-test-expect.xml new file mode 100644 index 0000000..16ad005 --- /dev/null +++ b/test/dyndns-test-expect.xml @@ -0,0 +1,36 @@ + + + + + + + + 1 + 0 + 0 + 300 + opnsense + + + + 1 + noip + + + + user + pass + all.ddnskey.com + 0 + + web_noip-ipv4 + 10 + 1 + 300 + wan + dyndns-description + + + + + diff --git a/test/dyndns-test.xml b/test/dyndns-test.xml new file mode 100644 index 0000000..16ad005 --- /dev/null +++ b/test/dyndns-test.xml @@ -0,0 +1,36 @@ + + + + + + + + 1 + 0 + 0 + 300 + opnsense + + + + 1 + noip + + + + user + pass + all.ddnskey.com + 0 + + web_noip-ipv4 + 10 + 1 + 300 + wan + dyndns-description + + + + + From e61b1f60540aa6ae7ca9e1643fbe421af6162d33 Mon Sep 17 00:00:00 2001 From: Farhad Nateghi <56291706+fnateghi@users.noreply.github.com> Date: Fri, 13 Sep 2024 10:00:51 +0200 Subject: [PATCH 5/5] requested changes in dyndns.yml, dyndns-test.xml,test.yml --- tasks/dyndns.yml | 1 - test/dyndns-test.xml | 29 ----------------------------- test/test.yml | 1 - 3 files changed, 31 deletions(-) diff --git a/tasks/dyndns.yml b/tasks/dyndns.yml index 788ff04..0e24a91 100644 --- a/tasks/dyndns.yml +++ b/tasks/dyndns.yml @@ -75,4 +75,3 @@ - settings when: - opn_dyndns_accounts is defined - - item.1.key != 'enable' diff --git a/test/dyndns-test.xml b/test/dyndns-test.xml index 16ad005..38af667 100644 --- a/test/dyndns-test.xml +++ b/test/dyndns-test.xml @@ -3,34 +3,5 @@ - - - 1 - 0 - 0 - 300 - opnsense - - - - 1 - noip - - - - user - pass - all.ddnskey.com - 0 - - web_noip-ipv4 - 10 - 1 - 300 - wan - dyndns-description - - - diff --git a/test/test.yml b/test/test.yml index 3dac9e8..68c5711 100644 --- a/test/test.yml +++ b/test/test.yml @@ -29,7 +29,6 @@ - name: restart dyndns debug: msg: fake handler - restart dyndns - tasks: - name: include default vars ansible.builtin.include_vars: