Answers: <p>At the bottom line I found this method as stable and reliable, in case you want to deploy via ansible.</p>
  
  <pre><code>### This play deploys a webapp war to an tomcat server
  
  - name: Copy the war file {{ webapp_name }}.war as {{ webapp_name }}.war.tmp to {{ webapp_destination_folder }}
    win_copy:
      src: files/{{ webapp_name }}.war
      dest: "{{ webapp_destination_folder }}\\{{ webapp_name }}.war.tmp"
      force: yes 
  
  - name: Remove current war file {{ webapp_destination_folder }}\{{ webapp_name }}.war
    win_file:
      path: "{{ webapp_destination_folder }}\\{{ webapp_name }}.war"
      state: absent
  
  - name: Wait until the webapp folder {{ webapp_destination_folder }}\{{ webapp_name }} is deleted
    win_wait_for:
      path: "{{ webapp_destination_folder }}\\{{ webapp_name }}xxx"
      state: absent
    register: folder_info
  
  - name: rename the {{ webapp_name }}.war.tmp to {{ webapp_name }}.war
    win_command: "cmd.exe /c rename {{ webapp_destination_folder }}\\{{ webapp_name }}.war.tmp {{ webapp_name }}.war"
    register: cmd_result 
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-09-04T19:26:48.337Z
Answers: Fine answer - possibly a typo with the "...xxx" in the wait_for statement? And while there's merit to some responses that insist Jenkins is better, sometimes you just need a simple task done with straightforward steps.
Answers: Peter Kelley
Answers: CC BY-SA 4.0
Answers: 2024-09-04T19:28:01.793Z
Answers: btw I did happen to need this, and adapted it to linux with no trouble.
Answers: Peter Kelley
Answers: CC BY-SA 3.0
Answers: 2017-12-12T16:57:45.637Z
Answers: 2017-12-12T16:57:45.637Z
Answers: Michael Hoeller
Answers: <p>I've got your point. Ansible is not the right choice for hot deployment to get rid of manual work and deploy the war files continuously to a server or where ever you want. Ansible is a configuration management tool. For this, you need an Automation deployment tool which is Jenkins. You need Jenkins in order to automate this. Create a Job, install a maven plugin within Jenkins and select the maven file before deploying the Code.</p>
  
  <p>For Tomcat, You need to define about the tomcat instance within Jenkins and write the script in such a way it will automatically deploy the war file everytime you commit the code.</p>
  
  <p>Best Practice,
  You better get a GIT repository and push your code there. Connect GitHub with Jenkins. The moment you will commit the code to GitHub it will automatically deploy the changes within tomcat through Jenkins and will Run the code.</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-12-12T21:36:33.597Z
Answers: You're speaking like the application version on a Middleware server wasn't a configuration thing...I've à hard time with this idea, the app version is no less a configuration step in the system than any other part
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2017-12-11T08:17:40.040Z
Answers: 2017-12-11T08:26:08.400Z
Answers: 2017-12-11T08:26:08.400Z
Answers: Mahirq8
Body: <p>Currently I build my app with maven and use the tomcat manager to hot deploy the war file (both on windows servers).</p>
  
  <p>Now I want to use ansible to move away from the manual process.</p>
  
  <ol>
  <li>Would it make sense to build with ansible? My assumption is, that it does not.</li>
  <li>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.</li>
  <li>Is there an other option to hot deploy the war file, which I might have overseen?</li>
  </ol>
  
Comments: CC BY-SA 3.0
Comments: 2017-12-08T16:15:41.413Z
Comments: There's a manager-script context exactly for that in tomcat manager application.
Comments: Tensibai
Tags: <ansible><deployment>
Title: How to hot deploy to Tomcat with Ansible
UserDisplayName: Michael Hoeller
ThreadText: # How to hot deploy to Tomcat with Ansible
  
  (Asked by: username_0 on 2017-12-08)
  
  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. Would it make sense to build with ansible? My assumption is, that it does not.
  2. 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. Is there an other option to hot deploy the war file, which I might have overseen?
  
  **Tags:** ansible, deployment
  
  > **Comments:**
  > **username_1**: There's a manager-script context exactly for that in tomcat manager application.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-12-12. Score: 2 | Accepted answer
  
  At the bottom line I found this method as stable and reliable, in case you want to deploy via ansible.
  
  ```
  ### This play deploys a webapp war to an tomcat server
  
  - name: Copy the war file {{ webapp_name }}.war as {{ webapp_name }}.war.tmp to {{ webapp_destination_folder }}
    win_copy:
      src: files/{{ webapp_name }}.war
      dest: "{{ webapp_destination_folder }}\\{{ webapp_name }}.war.tmp"
      force: yes 
  
  - name: Remove current war file {{ webapp_destination_folder }}\{{ webapp_name }}.war
    win_file:
      path: "{{ webapp_destination_folder }}\\{{ webapp_name }}.war"
      state: absent
  
  - name: Wait until the webapp folder {{ webapp_destination_folder }}\{{ webapp_name }} is deleted
    win_wait_for:
      path: "{{ webapp_destination_folder }}\\{{ webapp_name }}xxx"
      state: absent
    register: folder_info
  
  - name: rename the {{ webapp_name }}.war.tmp to {{ webapp_name }}.war
    win_command: "cmd.exe /c rename {{ webapp_destination_folder }}\\{{ webapp_name }}.war.tmp {{ webapp_name }}.war"
    register: cmd_result 
  
  ```
  
  > **Comments:**
  > **username_2**: Fine answer - possibly a typo with the "...xxx" in the wait_for statement? And while there's merit to some responses that insist Jenkins is better, sometimes you just need a simple task done with straightforward steps.  
  > **username_2**: btw I did happen to need this, and adapted it to linux with no trouble.  
  
  ---
  
  ### Answer by username_3 on 2017-12-11. Score: 1
  
  I've got your point. Ansible is not the right choice for hot deployment to get rid of manual work and deploy the war files continuously to a server or where ever you want. Ansible is a configuration management tool. For this, you need an Automation deployment tool which is Jenkins. You need Jenkins in order to automate this. Create a Job, install a maven plugin within Jenkins and select the maven file before deploying the Code.
  
  For Tomcat, You need to define about the tomcat instance within Jenkins and write the script in such a way it will automatically deploy the war file everytime you commit the code.
  
  Best Practice,
  You better get a GIT repository and push your code there. Connect GitHub with Jenkins. The moment you will commit the code to GitHub it will automatically deploy the changes within tomcat through Jenkins and will Run the code.
  
  > **Comments:**
  > **username_1**: You're speaking like the application version on a Middleware server wasn't a configuration thing...I've à hard time with this idea, the app version is no less a configuration step in the system than any other part  
  
  ---
  
  