Skip to content

Instantly share code, notes, and snippets.

@zerwes
Last active September 10, 2024 13:24
Show Gist options
  • Save zerwes/356a8cc901ac315c9b04841ea63a3b8c to your computer and use it in GitHub Desktop.
Save zerwes/356a8cc901ac315c9b04841ea63a3b8c to your computer and use it in GitHub Desktop.
ansible community.general.xml strange behavior on empty tags
# ansible-playbook -D testxmlemptytag.yml
PLAY [localhost] ************************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************
ok: [127.0.0.1]
TASK [ansible.builtin.copy] *************************************************************************************************************************************************
changed: [127.0.0.1]
TASK [community.general.xml] ************************************************************************************************************************************************
--- before
+++ after
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<a>
<b>
- <x>xxx</x>
+ <x>xx</x>
<y>yyy</y>
<z>zzz</z>
</b>
changed: [127.0.0.1] => (item={'key': 'x', 'value': 'xx'})
--- before
+++ after
@@ -2,7 +2,7 @@
<a>
<b>
<x>xx</x>
- <y>yyy</y>
+ <y></y>
<z>zzz</z>
</b>
</a>
changed: [127.0.0.1] => (item={'key': 'y', 'value': None})
--- before
+++ after
@@ -3,6 +3,6 @@
<b>
<x>xx</x>
<y/>
- <z>zzz</z>
+ <z></z>
</b>
</a>
changed: [127.0.0.1] => (item={'key': 'z', 'value': None})
<a>
<b>
<x>xxx</x>
<y>yyy</y>
<z>zzz</z>
</b>
</a>
---
# https://github.com/ansible-collections/community.general/issues/8361
- hosts: localhost
gather_facts: true
become: no
vars:
abctags:
x: xx
y:
z:
#alibeit:
tasks:
- ansible.builtin.copy:
src: testxmlemptytag-original.xml
dest: testxmlemptytag.xml
remote_src: true
- community.general.xml:
path: testxmlemptytag.xml
xpath: /a/b/{{ item.key }}
value: "{{ item.value }}"
pretty_print: true
with_dict: "{{ abctags }}"
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment