|
| 1 | +- name: Common tool setup on all the servers |
| 2 | + hosts: appsrvgrp |
| 3 | + become: yes |
| 4 | + vars: |
| 5 | + tom_url: https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz |
| 6 | + |
| 7 | + tasks: |
| 8 | + - name: Install JDK on Centos 6/7 |
| 9 | + yum: |
| 10 | + name: java-1.8.0-openjdk.x86_64 |
| 11 | + state: present |
| 12 | + when: ansible_distribution == 'CentOS' |
| 13 | + |
| 14 | + - name: Install JDK on Ubuntu 14/15/16/18 |
| 15 | + apt: |
| 16 | + name: openjdk-8-jdk |
| 17 | + state: present |
| 18 | + update_cache: yes |
| 19 | + when: ansible_distribution == 'Ubuntu' |
| 20 | + |
| 21 | + - name: Download Tomcat Tar Ball/Binaries |
| 22 | + get_url: |
| 23 | + url: "{{tom_url}}" |
| 24 | + dest: /tmp/tomcat-8.tar.gz |
| 25 | + |
| 26 | + - name: Add tomcat group |
| 27 | + group: |
| 28 | + name: tomcat |
| 29 | + state: present |
| 30 | + |
| 31 | + - name: Add tomcat user |
| 32 | + user: |
| 33 | + name: tomcat |
| 34 | + group: tomcat |
| 35 | + shell: /bin/nologin |
| 36 | + home: /usr/local/tomcat8 |
| 37 | + |
| 38 | + - file: |
| 39 | + path: /tmp/tomcat8 |
| 40 | + state: directory |
| 41 | + |
| 42 | + - name: Extract tomcat |
| 43 | + unarchive: |
| 44 | + src: /tmp/tomcat-8.tar.gz |
| 45 | + dest: /tmp/tomcat8/ |
| 46 | + remote_src: yes |
| 47 | + list_files: yes |
| 48 | + register: unarchive_info |
| 49 | + |
| 50 | + - debug: |
| 51 | + msg: "{{unarchive_info.files[0].split('/')[0]}}" |
| 52 | + |
| 53 | + - name: Synchronize /tmp/tomcat8/tomcat_cont /usr/local/tomcat8. |
| 54 | + synchronize: |
| 55 | + src: "/tmp/tomcat8/{{unarchive_info.files[0].split('/')[0]}}/" |
| 56 | + dest: /usr/local/tomcat8/ |
| 57 | + delegate_to: "{{ inventory_hostname }}" |
| 58 | + |
| 59 | + - name: Change ownership of /usr/local/tomcat8 |
| 60 | + file: |
| 61 | + path: /usr/local/tomcat8 |
| 62 | + owner: tomcat |
| 63 | + group: tomcat |
| 64 | + recurse: yes |
| 65 | + |
| 66 | + - name: Setup tomcat SVC file on Centos 7 |
| 67 | + template: |
| 68 | + src: templates/epel7-svcfile.j2 |
| 69 | + dest: /etc/systemd/system/tomcat.service |
| 70 | + mode: "a+x" |
| 71 | + when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '7' |
| 72 | + |
| 73 | + - name: Setup tomcat SVC file on Centos 6 |
| 74 | + template: |
| 75 | + src: templates/epel6-svcfile.j2 |
| 76 | + dest: /etc/init.d/tomcat |
| 77 | + mode: "a+x" |
| 78 | + when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '6' |
| 79 | + |
| 80 | + - name: Setup tomcat SVC file on ubuntu 14/15 |
| 81 | + template: |
| 82 | + src: templates/ubuntu14_15-svcfile.j2 |
| 83 | + dest: /etc/init.d/tomcat |
| 84 | + mode: "a+x" |
| 85 | + when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version < '16' |
| 86 | + |
| 87 | + - name: Setup tomcat SVC file on ubuntu 16 and 18 |
| 88 | + template: |
| 89 | + src: templates/ubuntu16-svcfile.j2 |
| 90 | + dest: /etc/systemd/system/tomcat.service |
| 91 | + mode: "a+x" |
| 92 | + when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version >= '16' |
| 93 | + |
| 94 | + - name: Reload tomcat svc config in ubuntu 14/15 |
| 95 | + command: update-rc.d tomcat defaults |
| 96 | + when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version < '16' |
| 97 | + |
| 98 | + - name: Reload tomcat svc config in Centos 6 |
| 99 | + command: chkconfig --add tomcat |
| 100 | + when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '6' |
| 101 | + |
| 102 | + - name: just force systemd to reread configs (2.4 and above) |
| 103 | + systemd: |
| 104 | + daemon_reload: yes |
| 105 | + when: ansible_distribution_major_version > '6' or ansible_distribution_major_version > '15' |
| 106 | + |
| 107 | + - name: Start & Enable TOmcat 8 |
| 108 | + service: |
| 109 | + name: tomcat |
| 110 | + state: started |
| 111 | + enabled: yes |
| 112 | + |
| 113 | + |
0 commit comments