Skip to content

Commit

Permalink
issue #46 : alias multivalue refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
zerwes committed Dec 14, 2023
1 parent 854af88 commit 42ce6f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
9 changes: 3 additions & 6 deletions tasks/alias.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tasks/aliasmultivalue.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 42ce6f3

Please sign in to comment.