# how to edit tomcat xml using xml module in ansible..

**URL:** <https://forum.ansible.com/t/how-to-edit-tomcat-xml-using-xml-module-in-ansible/28001>\
**Category:** Ansible Project\
**Created:** [July 10, 2018, 7:46am UTC](https://forum.ansible.com/t/how-to-edit-tomcat-xml-using-xml-module-in-ansible/28001 "2018-07-10T07:46:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [July 10, 2018, 7:46am UTC](https://forum.ansible.com/t/how-to-edit-tomcat-xml-using-xml-module-in-ansible/28001/1 "2018-07-10T07:46:29Z")

</div>

Hi ,

I am trying to use the xml module to edit the tomcat’s server.xml to add few lines .but it not getting idea as what to provide the xpath. In the below ,want to add few line( like **acceptCount=“somecontent”,** \*\*maxConnections=“somecontent”,\*\***connectionTimeout=“some content” )** under the .Currently using the blockinfile but thats not the right way of editing it. Could you please help in knowing how to use xml module to implement.

_ **`<``Service` `name``=``"Catalina"`** `>`_  
_` **##to add few lines here using xml module###** `_

_````\<`Connector` `port`=`"8080"` `protocol`=`"HTTP/1.1"`_

> _`*<br> | *```connectionTimeout`=``“20000”`_ |
> 
> - | - |

> _`*<br> | *```redirectPort`=``“8443”` `/\>`_ |
> 
> - | - |

> _`*<br> | *`<`Connector` `port`=`“8009”` `protocol`=`“AJP/1.3”` `redirectPort`=`“8443”` `/`_ |
> 
> - | - |

`<``Engine` `name``=``"Catalina"` `defaultHost``=``"localhost"``>`

> ``_` **##to add few more lines here using xml module###** `_ | |
> 
> - | - |

> `<br> | `<`Realm` `className`=`“org.apache.catalina.realm.LockOutRealm”``\>` |
> 
> - | - |

> `<br> | `<`Realm` `className`=`“org.apache.catalina.realm.UserDatabaseRealm”` |
> 
> - | - |

> `<br> | `resourceName`=`"UserDatabase"`/\>` |
> 
> - | - |

> `<br> | `</`Realm``\>` |
> 
> - | - |

I am using blockinfile as below :

- blockinfile:  
path: /etc/tomcat/server.xml  
insertafter: ‘’  
marker: “# {mark} ANSIBLE MANAGED BLOCK insertion 1”  
content: |  
**acceptCount=“somecontent”**

**maxConnections=“somecontent”**  
**connectionTimeout=“some content”**

Thank you.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [July 10, 2018, 8:36am UTC](https://forum.ansible.com/t/how-to-edit-tomcat-xml-using-xml-module-in-ansible/28001/2 "2018-07-10T08:36:31Z")

</div>

I would recommend using template module instead - maybe you have lots of different tomcat configurations to support, or tomcat versions, so it might not work for you, but unless you are changing server.xml a great deal it might be quicker to just use template and move on to solving other problems.

Hope this helps

Jon

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [July 10, 2018, 12:29pm UTC](https://forum.ansible.com/t/how-to-edit-tomcat-xml-using-xml-module-in-ansible/28001/3 "2018-07-10T12:29:49Z")

</div>

Thank you for the reply Jon, thats a better suggestion but i wanted to know how to editing couple of lines using xml modules…

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [July 11, 2018, 10:01am UTC](https://forum.ansible.com/t/how-to-edit-tomcat-xml-using-xml-module-in-ansible/28001/4 "2018-07-11T10:01:37Z")

</div>

also the examples on how to use xml module is very vague if we search in google and in anisble docs…i would request if anyone can give some insight into it.
