I want to edit a XML and add a new element to it using Ansible. I am able to edit the XML and add the element using the below Ansible code. The XML is not getting updated in the require format. Tried different things but its not working.
- name: Add a element to the 'business' element
community.general.xml:
path: /tmp/temp.xml
xpath: /x:Activity/x:ActivityDetails/x:listOfActivityAttribute/x:Testattribute
namespaces:
x: "http://test.com/xsd/crm/v1/Activity/ManageInternalCustomerChange"
attribute: validatedon
value: 1976-08-05
The XML result is as below
<ActivityDetails>
<activityId>bcb45088-21aa-4ec4-b453-5f08af0fc612</activityId>
<activityType>ServiceIdRecordUpdate</activityType>
<activityStartDate>%DateTime%</activityStartDate>
<listOfActivityAttribute>
<activityAttribute>
<name>CustomerId</name>
<value>%CustomerId%</value>
</activityAttribute>
<activityAttribute>
<name>AssetInstanceId</name>
<value>%AssetInstanceId%</value>
</activityAttribute>
<activityAttribute>
<name>ServiceId</name>
<value>%ServiceId%</value>
</activityAttribute>
<activityAttribute>
<name>SupplierServiceId</name>
<value>%SupplierServiceId%</value>
</activityAttribute>
<Testattribute
<validatedon=\\"1976-08-05\\"/>
</listOfActivityAttribute>
</ActivityDetails>
</Activity>
Expected output
<ActivityDetails>
<activityId>bcb45088-21aa-4ec4-b453-5f08af0fc612</activityId>
<activityType>ServiceIdRecordUpdate</activityType>
<activityStartDate>%DateTime%</activityStartDate>
<listOfActivityAttribute>
<activityAttribute>
<name>CustomerId</name>
<value>%CustomerId%</value>
</activityAttribute>
<activityAttribute>
<name>AssetInstanceId</name>
<value>%AssetInstanceId%</value>
</activityAttribute>
<activityAttribute>
<name>ServiceId</name>
<value>%ServiceId%</value>
</activityAttribute>
<activityAttribute>
<name>SupplierServiceId</name>
<value>%SupplierServiceId%</value>
</activityAttribute>
<Testattribute>
<name>validatedon</name>
<value>1976-08-05</value>
</Testattribute>
</listOfActivityAttribute>
</ActivityDetails>
</Activity>`
Tried adding it as a child node as well but didn't work. It didn't do anything .
- name: Add a element to the 'business' element
community.general.xml:
path: /tmp/temp.xml
xpath: /x:Activity/x:ActivityDetails/x:listOfActivityAttribute/x:Testattribute
namespaces:
x: "http://capabilities.nat.bt.com/xsd/crm/v1/Activity/ManageInternalCustomerChange"
add_children:
- validatedon: 1976-08-05
<Testattribute <validatedon=\\"1976-08-05\\"/>seems really buggy to me, are you sure Ansible produces you that?