0

I execute an Ansible playbook with an ansible user. The playbook executes properly, with no errors in the application log, no errors in the Ansible log. This .war usually deploys with user "tomcat" when the deploy is manual.

Could this be the cause of the problem? Execute playbook with different users

This is my playbook (syntax is correct):

- name: Deploy war
  hosts: grupo1
  tasks:
    - name: Stop Tomcat
      command: systemctl stop tomcat

    - name: Delete old war1
      command: rm -rf /opt/tomcat/catalina_base/webapps.old/portal-admin
      args:
        warn: false

    - name: Delete old war
      command: rm -rf /opt/tomcat/catalina_base/webapps.old/portal-client
      args:
        warn: false

    - name: Copy the old war
      copy:
        src: /opt/tomcat/catalina_base/webapps/portal-client
        remote_src: true
        dest: /opt/tomcat/catalina_base/webapps.old/

    - name: Copy the old war2
      copy:
        src: /opt/tomcat/catalina_base/webapps/portal-admin
        remote_src: true
        dest: /opt/tomcat/catalina_base/webapps.old/


    - name: delte the war fileclient
      shell: /bin/rm -rf /opt/tomcat/catalina_base/webapps/portal-client/*
      args:
        warn: false

    - name: deploy warclient
      command: unzip /tmp/portal-client.war -d /opt/tomcat/catalina_base/webapps/portal-client/
        args:
          warn: false

    - name: delete the war fileadmin
      shell: /bin/rm -rf /opt/tomcat/catalina_base/webapps/portal-admin/*
      args:
        warn: false

    - name: deploy waradmin
      command: unzip /tmp/portal-admin.war -d /opt/tomcat/catalina_base/webapps/portal-admin/
      args:
        warn: false

    - name: Start tomcat
      command: systemctl start tomcat


The error when I execute the playbook is

Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /portal-client/cm/misalud/.

Reason: Error reading from remote server
2
  • There are some problems with your question and with your approach to Ansible. On the question, it's not really clear what is the error, as this is an Ansible question and you say there were no errors on the playbook; also, the error you pasted does not look to come from Ansible. Please describe what is the actual error you're facing, and add logs Commented Jan 10, 2021 at 4:17
  • On the approach to Ansible, you're using command and shell all around, for stuff you could be using Ansible modules for. For removing stuff, for example, use file module with state: absent; for service stop/start, use the service module instead of systemctl. Check also unarchive. The use of modules makes your playbook more readable and more portable. shell, command and similar modules should be used only when the functionality is not covered by Ansible. Commented Jan 10, 2021 at 4:22

1 Answer 1

2

First - @caxcaxcoatl is completly right - your playbook is not Ansible, it is a bash script inside Ansible and that isn't Ansible.

Your error doesn't have something to do with your playbook, but with that, what the playbook is doing. You're redeploying an application and then the proxy in front of the Tomcat cannot read the response from your Tomcat. So your deployment is wrong, has some failures, what ever. You should have a look at your Tomcat HTTP response (without the Proxy in front) direct on the machine (with curl, telnet or whatever). Maybe you should also check the logs of Tomcat to get the error. The proxy sends the error, because the Tomcat is answering with a 500 HTTP error code, when the proxy hits /portal-client/cm/misalud/.

To give you a hint, how a playbook could look like (of course this wasn't the question, and it could be done much better then this with includes for a unspecific WAR and just call include_tasks on all available WARs in the main playbook, or with a Ansible module written in Python just giving the params of the new WAR etc.):

- name: Deploy war
  hosts: grupo1
  vars:
    webapps_cur "/opt/tomcat/catalina_base/webapps"
    webapps_old: "/opt/tomcat/catalina_base/webapps.old"
  tasks:
    - name: "Stop Tomcat"
      systemd:
        name: tomcat
        state: stopped

    - name: "Delete old Backup WARs"
      file:
        path: "{{ webapps_old }}/{{ item }}"
        state: absent
      with_items:
        - "portal-admin"
        - "portal-client"

    - name: "Backup the current WARs"
      copy:
        src: "{{ webapps_cur }}/{{ item }}"
        dest: "{{ webapps_old }}/{{ item }}"
        remote_src: true
      with_items:
        - "portal-admin"
        - "portal-client"

    - name: "Delete the current WARs"
      file:
        path: "{{ webapps_cur }}/{{ item }}"
        state: absent
      with_items:
        - "portal-admin"
        - "portal-client"

    - name: "Deploy new WARs"
      unarchive:
        src: "/tmp/{{ item }}.war"
        dest: "{{ webapps_cur }}/{{ item }}"
        user: "tomcat"
        group: "tomcat"
      with_items:
        - "portal-admin"
        - "portal-client"

    - name: "Start Tomcat"
      systemd:
        name: tomcat
        state: started

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.