It is not possible to add a new element to an empty element. To prevent this I have added logic to add an element when the node does not contain any childnodes. Please take a look at the additional information for more details and examples.
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
win_xml
ADDITIONAL INFORMATION
My goal was to add a simple httpRedirect configuration in an existing web.config of an IIS server. In my example, I only had an empty configuration as by base XML.
SUMMARY
It is not possible to add a new element to an empty element. To prevent this I have added logic to add an element when the node does not contain any childnodes. Please take a look at the additional information for more details and examples.
ISSUE TYPE
COMPONENT NAME
win_xml
ADDITIONAL INFORMATION
My goal was to add a simple httpRedirect configuration in an existing web.config of an IIS server. In my example, I only had an empty configuration as by base XML.
Playbook:
Base XML:
In this example, no changes are made. When adjusting the XML by adding a text element:
Base XML:
Result XML:
Behavior when using the pull request adjustment:
Base XML:
Result:
Tested this in two separate environments on both Windows Server 2019 and Windows Server 2022 with the ansible versions: 2.10.17 & 2.13.7