From 42ce6f3641c49f08760fe2ccb2e129a1ccbe955d Mon Sep 17 00:00:00 2001 From: Klaus Zerwes Date: Thu, 14 Dec 2023 21:54:27 +0100 Subject: [PATCH] issue #46 : alias multivalue refactored --- tasks/alias.yml | 9 +++------ tasks/aliasmultivalue.yml | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 tasks/aliasmultivalue.yml diff --git a/tasks/alias.yml b/tasks/alias.yml index 65cb3e2..956fcb8 100644 --- a/tasks/alias.yml +++ b/tasks/alias.yml @@ -63,15 +63,12 @@ when: item.1.value is defined - name: multivalue aliases - delegate_to: localhost - community.general.xml: - path: "{{ local_config_path }}" - xpath: "/opnsense/OPNsense/Firewall/Alias/aliases/alias[@uuid='{{ item.0.uuid }}']/{{ item.1.key }}" - value: "{{ item.1.list | join('\n') }}" - pretty_print: true + ansible.builtin.include_tasks: aliasmultivalue.yml with_subelements: - "{{ opn_alias | default([]) }}" - settings + loop_control: + label: "{{ item.0.uuid }} {{ item.1.key }}" when: item.1.list is defined # valid types can be determined from diff --git a/tasks/aliasmultivalue.yml b/tasks/aliasmultivalue.yml new file mode 100644 index 0000000..5256c67 --- /dev/null +++ b/tasks/aliasmultivalue.yml @@ -0,0 +1,24 @@ +--- + +- name: get current setting from xml for multivalue alias + delegate_to: localhost + community.general.xml: + path: "{{ local_config_path }}" + xpath: "/opnsense/OPNsense/Firewall/Alias/aliases/alias[@uuid='{{ item.0.uuid }}']/{{ item.1.key }}" + content: text + register: _configured_multivalue_alias + ignore_errors: true # do not fail if node not exists + +- debug: + var: _configured_multivalue_alias + +- name: set multivalue alias + delegate_to: localhost + community.general.xml: + path: "{{ local_config_path }}" + xpath: "/opnsense/OPNsense/Firewall/Alias/aliases/alias[@uuid='{{ item.0.uuid }}']/{{ item.1.key }}" + value: "{{ item.1.list | join('\n') }}" + pretty_print: true + when: + - _configured_multivalue_alias.failed | bool or _configured_multivalue_alias.matches[0][item.1.key].split('\n') | sort != item.1.list | sort +