Ansible Playbook:
Step 1:
In your group variables:
javaserver.yml
---
SRC:/path-of-source-file/example.war
DES: /destination-path/
CATALINA_HOME: /apps/opt/apache-tomcat-7.0.64
PROJECT_CODE: XYZ
Step 2:
In your main playbook:
---
- hosts: javaserver
user: root
roles:
- javadeploycode
Here "javaserver" is the group name which is defined in hosts file.
Step 3:
In your javadeploycode directory main.yml is
roles/javadeploycode/tasks/main.yml
# make sure your groupname is same as variable file in step 1.
---
- name: stop tomcat
command: {{ CATALINA_HOME }}/bin/shutdown.sh
- name: removing old war file
command: rm -rf {{ CATALINA_HOME }}/webapps/{{ PROJECT_CODE }}.war
- name: removing old file
command: rm -rf {{ CATALINA_HOME }}/webapps/{{ PROJECT_CODE }}-application
- name: copy war file from {{ SRC }} to destination path {{ DES }}
# synchronize: src={{ SRC }} dest={{ DES }} checksum=yes recursive=yes delete=yes
# ignore_errors: yes
copy: src={{ SRC }} dest={{ DES }}
- name: start tomcat
shell: source /home/tomcat/.bash_profile && {{ CATALINA_HOME }}/bin/startup.sh
Find github code here:
https://github.com/kumarsuresh521-netsol/Ansible_Playbook_To_Start_Tomcat
Find github code here:
https://github.com/kumarsuresh521-netsol/Ansible_Playbook_To_Start_Tomcat
Well said .Keep updating Devops Online Training
ReplyDelete