# How to hot deploy to tomcat with ansible?

**URL:** <https://forum.ansible.com/t/how-to-hot-deploy-to-tomcat-with-ansible/26229>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [December 8, 2017, 3:01pm UTC](https://forum.ansible.com/t/how-to-hot-deploy-to-tomcat-with-ansible/26229 "2017-12-08T15:01:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Hoeller](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@Michael\_Hoeller](https://forum.ansible.com/u/Michael_Hoeller)\
**Post date:** [December 8, 2017, 3:01pm UTC](https://forum.ansible.com/t/how-to-hot-deploy-to-tomcat-with-ansible/26229/1 "2017-12-08T15:01:33Z")

</div>

Hello

Currently I build my app with maven and use the tomcat manager to hot deploy the war file (both on windows servers).

Now I want to use ansible to move away from the manual process.

1. 
  1. Would it make sense to build with ansible? My assumption is, that id does not.

2. 
  1. How could I use the tomcat manager to hot deploy, triggered by ansible. I have searched the web but I did not find a solution.

3. 
  1. Is there an other option to hot deploy the war file, which I might have overseen?  
Thanks a lot 🙂  
Michael

---

<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:** [December 10, 2017, 8:25pm UTC](https://forum.ansible.com/t/how-to-hot-deploy-to-tomcat-with-ansible/26229/2 "2017-12-10T20:25:36Z")

</div>

I can recommend using Jenkins for running your maven builds.

I don't use the Tomcat manager app to hot deploy apps, but I imagine you could use the uri or win\_uri module to post your war file. You can run remote ansible playbooks using the 'Send Files Over SSH' Jenkins plugin - and probably other ways too, such as using the AWX or Tower REST api. While this might feel like extra work just to deploy your app into a development or test environment, you can reuse the same playbook to deploy to production.

Ansible is good for doing rolling updates when you have apps running in a cluster. By setting 'serial: 1' you can update one server at a time and avoid downtime, if that is important for you.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![akazia.info](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@akazia.info](https://forum.ansible.com/u/akazia.info)\
**Post date:** [December 10, 2017, 8:58pm UTC](https://forum.ansible.com/t/how-to-hot-deploy-to-tomcat-with-ansible/26229/3 "2017-12-10T20:58:31Z")

</div>

Hello

part 1:  
according to [this post](https://groups.google.com/forum/#!topic/ansible-project/fo4u-0CFZDU)the uri does not support src… So no upload can take place. Also the doc seem not to mention src for the uri.  
does anyone fond a workaround beside doing the curl command via a ansible shell? Would be great.

part 2:  
Jon, when you don 't use the tomcat manager for a hot deployment, what else to you use what you can recommend?

Thanks a lot  
Michael

---

<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:** [December 17, 2017, 8:45am UTC](https://forum.ansible.com/t/how-to-hot-deploy-to-tomcat-with-ansible/26229/4 "2017-12-17T08:45:01Z")

</div>

Sorry I thought I had replied to this one days ago.

Yes you are right uri doesn't do that so curl would be the only other option I can think of right now.

The way we do releases without down time is to have a minimum of two vms running Tomcat and a load balancer in front of them. To deploy, we stop one Tomcat so that the load balancer stops sending it requests, then we just copy over the new war file and start the Tomcat again. Ansible polls a url that is served by the Tomcat app, so we can tell when it has finished deploying, then we just repeat the installation steps on the other Tomcat vm(s). Ansible makes this super easy as you just specify

serial: 1

in the playbook.

Ideally I would like to update the load balancer and take each vm out of the pool in turn, rather than relying on the health check performed by the load balancer to reroute traffic, but that is difficult for us as the load balancer is a shared resource used by other teams. It hasn't been a problem for us in practice though.

---

<div class="post-metadata">

**Author:** ![nbmprivat](https://avatars.discourse-cdn.com/v4/letter/n/cab0a1/32.png) [@nbmprivat](https://forum.ansible.com/u/nbmprivat)\
**Post date:** [December 18, 2017, 1:30pm UTC](https://forum.ansible.com/t/how-to-hot-deploy-to-tomcat-with-ansible/26229/5 "2017-12-18T13:30:13Z")

</div>

I have done this last week.

Procedure:

1. Download the .zip installation file for windows
2. Unpack and copy to your ansible host (most likely roles/rolename/files/tomcat)
3. Copy the binaries via ansible to your win hosts (c:\program files\apache tomcat foundation\tomcat x.x)
4. Run service.bat in the bin folder
5. Configure the service with ansible
6. Run startup.bat form bin folder

`

- name: Copy Apache Tomcat binaries to provisioned VM  
win\_copy:  
src: “{{ role\_path }}/files/tomcat/{{ tomcat\_64 }}”  
dest: “{{ tomcat\_64\_path }}”

- name: Install Tomcat service on provisioned VM  
win\_command: service.bat install  
args:  
chdir: “{{ tomcat\_64\_path }}\{{ tomcat\_64 }}\bin\”

- name: Set Tomcat startup mode to auto and ensure it is started  
win\_service:  
name: tomcat\*  
start\_mode: auto  
state: started

- name: Startup Tomcat on provisioned VM  
win\_command: startup.bat  
args:  
chdir: “{{ tomcat\_64\_path }}\{{ tomcat\_64 }}\bin\”

`

---

<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:** [December 19, 2017, 5:16pm UTC](https://forum.ansible.com/t/how-to-hot-deploy-to-tomcat-with-ansible/26229/6 "2017-12-19T17:16:11Z")

</div>

I’d recommend setting up tomcat as a service on windows.  
I’d fear that if you start tomcat using a .bat file, when your playbook completes your tomcat process may get ended.

Also once you have tomcat set up as a service, you can use win\_service to start/stop/restart it.

You can configure the service options from the command line like this:

`

- name: set tomcat parameters for startup  
win\_shell: '{{ tomcat\_home }}\bin\tomcat8.exe update --Startup=auto --JvmMs=2000 --JvmMx=2000 --JvmOptions=“-Dcatalina  
.home={{ tomcat\_home }};-Dcatalina.base={{ tomcat\_home }};-Djava.endorsed.dirs={{ tomcat\_home }}\endorsed;-Djava.io.tm  
pdir={{ tomcat\_home }}\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config  
.file={{ tomcat\_home }}\conf\logging.properties;-Xrunjdwp:transport=dt\_socket,address=8787,server=y,suspend=n;-Xms1500M;  
-Xmx1500M;”  
`

Hope this helps,

Jon
