Search This Blog

Sunday, 21 February 2021

Ansible playbook for tomcat installation and configuration

Step 1) I used ansible-galaxy to create a folder structure for tomcat playbook

[osboxes@master ansible-projects]$ ansible-galaxy init tomcat
- Role tomcat was created successfully

 [osboxes@master ansible-projects]$ tree tomcat/
tomcat/
├── defaults
│   └── main.yml
├── files
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── README.md
├── tasks
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml

8 directories, 8 files


Step 2) I have create playbook for tomcat installation and instance creation. You may download the source code from github repository.


[osboxes@master ansible-projects]$ cat install_configure_tomcat.yml
---
- hosts: all
  become: yes
  become_method: sudo

  roles:
    - role: "roles/tomcat90"


[osboxes@master ansible-projects]$ cat inventory.txt
tomcathost01



[osboxes@master ansible-projects]$ tree
.
├── install_configure_tomcat.yml
├── inventory.txt
└── roles
    └── tomcat90
        ├── defaults
        │   └── main.yml
        ├── files
        │   └── bash_profile
        ├── handlers
        │   └── main.yml
        ├── meta
        │   └── main.yml
        ├── README.md
        ├── tasks
        │   ├── boot.yml
        │   ├── filesystem.yml
        │   ├── install.yml
        │   ├── main.yml
        │   └── validate.yml
        ├── templates
        │   ├── setenv.sh.j2
        │   └── tomcat.service.j2
        ├── tests
        │   ├── inventory
        │   └── test.yml
        └── vars
            └── main.yml

10 directories, 17 files

Step 3) Run Ansible playbook 

[osboxes@master ansible-projects]$ ansible-playbook install_configure_tomcat.yml -i inventory.txt

PLAY [all] **************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************
ok: [tomcathost01]

TASK [roles/tomcat90 : check if the tomcat instance already present] ****************************************************************************************
ok: [tomcathost01]

TASK [roles/tomcat90 : fail] ********************************************************************************************************************************
skipping: [tomcathost01]

TASK [roles/tomcat90 : create a directory for tomcat jdk location] ******************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : create a directory for tomcat product location] **************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : create a directory for tomcat product location] **************************************************************************************
ok: [tomcathost01]

TASK [roles/tomcat90 : create a directory for tomcat instance location] *************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : create a directory for tomcat log location] ******************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : Installing Java] *********************************************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : Create a symlink for jdk] ************************************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : Copy bash_profile to destination server for setting up JAVA_HOME] ********************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : Source the .bash_profile] ************************************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : Download tomcat binaries] ************************************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : Install tomcat] **********************************************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : Create a symlinks for tomcat products] ***********************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : Create a new tomcat instance] ********************************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : delete log directory] ****************************************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : Create a log symlinks] ***************************************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : deploy setenv.sh.j2 to /home/osboxes/instances/poc-tomcat-instance/bin] **************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : cleanup tomcat downloads] ************************************************************************************************************
ok: [tomcathost01]

TASK [roles/tomcat90 : deploy tomcat.service.j2 to /etc/systemd/system/tomcat.service] **********************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : load tomcat service] *****************************************************************************************************************
changed: [tomcathost01]

TASK [roles/tomcat90 : enable tomcat service] ***************************************************************************************************************
ok: [tomcathost01]

TASK [roles/tomcat90 : starting the tomcat instance] ********************************************************************************************************
changed: [tomcathost01]

PLAY RECAP **************************************************************************************************************************************************
tomcathost01               : ok=23   changed=18   unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

No comments: