0

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"
        }
    }
}
yagmoth555
  • 16,758
  • 4
  • 29
  • 50
eliassal
  • 101
  • 1
  • 1
    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. – larsks Jan 22 '23 at 14:38
  • 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 Jan 23 '23 at 10:33
  • @larsks, I think that your file is different than mine. I opened tomcat-users.xml, removed all commented elements, removed the xmlns from the element as follows 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 Jan 23 '23 at 10:50
  • 1
    After reading some docs, I found that I should add the namespaces in the ansible block, once I did that, update went through – eliassal Jan 23 '23 at 12:41

0 Answers0