I have the following XML file and trying to replace the values for each attribute based on created dictionary, but having troubles to iterate over the complex dict.
config.xml file
<?xml version='1.0' encoding='UTF-8'?>
<SystemConfiguration>
<Component FQDD="iDRAC.Embedded.1">
<Attribute Name="IPv4Static.1#DNS1">1.1.1.1</Attribute>
<Attribute Name="IPv4Static.1#DNS2">2.2.2.2</Attribute>
</Component>
<Component FQDD="System.Embedded.1">
<Attribute Name="LCD.1#Configuration">null</Attribute>
</Component>
</SystemConfiguration>
Ansible playbook looks like this:
---
- name: modify XML
hosts: localhost
gather_facts: no
vars:
xml_file: config.xml
comp:
iDRAC.Embedded.1: [
{name: "IPv4Static.1#DNS1", val: 10.10.10.10},
{name: "IPv4Static.1#DNS2", val: 20.20.20.20}]
System.Embedded.1: [
{name: "LCD.1#Configuration", val: "OS System Name"}]
tasks:
- name: replace value in XML
xml:
path: "{{ xml_file }}"
xpath: /SystemConfiguration/Component[@FQDD={{ item.key }}]/Attribute[@Name="{{ item.value.name }}"]
value: item.value.val
loop: "{{ lookup('dict', comp,wantlist=true) }}"
I'm not able to get the values from the list inside the dictionary and no idea how to approach this.