Score:0

Ansible xml add_children not working

th flag

I have an ansible playbook in which I try to add xml elements to an xml file (tomcat-users.xml) as follows

- name: Update Scheme Option in tomcat-users.xml add role user elements
     become: yes
     become_user: tomcat
     xml:
       file: /opt/tomcat8/conf/tomcat-users.xml
       xpath: /tomcat-users 
       pretty_print: true
       add_children:
         - role:
             rolename: "manager-gui"
         - user:
             username: "tomcat"
             password: "tomcat"
             roles: "manager-gui"

When I run the playbook, it finishes indicating OK for the step but when I check/Open the xml file, nothing has been added. Is there any somthing wrong with the syntax? Thanks


Thanks but still on my side is not going through, I created a yml file where only there is the code above, ran the ansible-playbook with "-vvv", I get OK but in the details it seems that it has changed nothing

ok: [192.168.1.41] => {
    "actions": {
        "namespaces": {},
        "state": "present",
        "xpath": "/tomcat-users"
    },
    "changed": false,
    "invocation": {
        "module_args": {
            "add_children": [
                {
                    "role": {
                        "rolename": "manager-gui"
                    }
                },
                {
                    "user": {
                        "password": "tomcat",
                        "roles": "manager-gui",
                        "username": "tomcat"
                    }
                }
            ],
            "attribute": null,
            "backup": false,
            "content": null,
            "count": false,
            "file": "/opt/tomcat8/conf/tomcat-users.xml",
            "input_type": "yaml",
            "insertafter": false,
            "insertbefore": false,
            "namespaces": {},
            "path": "/opt/tomcat8/conf/tomcat-users.xml",
            "pretty_print": true,
            "print_match": false,
            "set_children": null,
            "state": "present",
            "strip_cdata_tags": false,
            "value": null,
            "xmlstring": null,
            "xpath": "/tomcat-users"
        }
    }
}
pt flag
I can't reproduce this behavior. When I run your playbook, it successfully modifies my `tomcat-users.xml` file to add both the new `role` and update the `tomcat` user.
eliassal avatar
th flag
I have just responded to your reply as I was not able to include the ansible response in the comment as there is a limit on text length
eliassal avatar
th flag
@larsks, I think that your file is different than mine. I opened tomcat-users.xml, removed all commented elements, removed the xmlns from the <tomcat-usres> element as follows <tomcat-usres></tomcat-usres> and playbook went through and file was updated, so I think it is because of the xmlns, what do you think? Is your tomcatusers file has the xmlns in the element?
eliassal avatar
th flag
After reading some docs, I found that I should add the namespaces in the ansible block, once I did that, update went through
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.