-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create multiple nodes? #117
Comments
Is this what you want to achieve? - hosts: localhost
roles:
- cmprescott.xml
tasks:
- name: Issue #117
xml:
file: test.xml
xpath: /root
add_children: "{{ item }}"
input_type: xml
with_items:
- <error-page><error-code>404</error-code><location>/error/404.html</location></error-page>
- <error-page><error-code>500</error-code><location>/error/500.html</location></error-page> Content of test.xml before running the play: <root/> Content of test.xml after running the play (manually reformatted): <?xml version='1.0' encoding='UTF-8'?>
<root>
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error/500.html</location>
</error-page>
</root> |
Hi, I got OK from the task but the file is not changed. I am using it to modify web.xml of Tomcat, but nothing happen. Code is here: Output of one iteration item:
Do you have idea what did I wrong? |
As I suspected, the problem is due to XML namespaces. You need to specify the namespaces argument to the <web-app xmlns="http://java.sun.com/xml/ns/j2ee" ... So, add this argument: namespaces:
j2ee: http://java.sun.com/xml/ns/j2ee and use this value for xpath: /j2ee:web-app |
Thank you Sir! |
I have only one problem: it is always update the xml file, so if I run twice it adds all element twice :/ |
The xml module is upstream now (and ships with Ansible v2.4). I am interested in improvements to the documentation upstream. You can open a PR with specific suggestions and we'll get them merged. Please close this issue, and if needed, open a new issue at: https://github.com/ansible/ansible/issues |
@KAMI911, would you please close this issue? |
Hi,
This is a support question (or feature request), rather than error report but how can I create structure like:
I have tried several ideas from with_items lists to add_children, but I was not able to crate such structure. I am using latest Ansible with latest xml library that is available here.
Thank you in advance!
The text was updated successfully, but these errors were encountered: