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.
-
- Would it make sense to build with ansible? My assumption is, that id does not.
-
- 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.
-
- Is there an other option to hot deploy the war file, which I might have overseen?
Thanks a lot
Michael
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
Hello
part 1:
according to this post 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
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.
I have done this last week.
Procedure:
- Download the .zip installation file for windows
- Unpack and copy to your ansible host (most likely roles/rolename/files/tomcat)
- Copy the binaries via ansible to your win hosts (c:\program files\apache tomcat foundation\tomcat x.x)
- Run service.bat in the bin folder
- Configure the service with ansible
- 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\”
`
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