Ansible Playbook for installing Tomcat on Ubuntu 18.0.4
Pre-requisites:
- Install Ansible on Ubuntu instance
- Ubuntu EC2 instance (target) where Tomcat needs to be installed. Click here to know how to create new EC2 using Ansible
- Setup SSH keys and upload public key into Ubuntu EC2 instance where Tomcat will be installed.
- Modify hosts/inventory file to add target Ec2 instance ip address/dns name.
- port 8080 is opened in firewall rule
Steps to setup SSH keys:
1. Login to Ansible management server/machine. Create SSH keys in Ansible host machine by executing the below command: (if you already have keys created, please skip this step)
ssh-keygen
enter three times..now you will see keys successfully created.
2. Execute the below command on Ansible management node and copy the public key content:
sudo cat ~/.ssh/id_rsa.pub
copy the above output.
3. Now login into target node where you want to install Tomcat, execute the below command to open the file
sudo vi /home/ubuntu/.ssh/authorized_k eys
type shift A and then enter now
and paste the key in the above file. please do not delete any existing values in this file.
4. Now go back to Ansible mgmt node, do changes in /etc/ansible/hosts file to include the node you will be installing software. Make sure you add public or private IP address of target node as highlighted below in red color:
sudo vi /etc/ansible/hosts
[My_Group]
xx.xx.xx.xx ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~ /.ssh/id_rsa ansible_python_interpreter=/us r/bin/python3
enter three times..now you will see keys successfully created.
2. Execute the below command on Ansible management node and copy the public key content:
sudo cat ~/.ssh/id_rsa.pub
copy the above output.
3. Now login into target node where you want to install Tomcat, execute the below command to open the file
sudo vi /home/ubuntu/.ssh/authorized_k
type shift A and then enter now
and paste the key in the above file. please do not delete any existing values in this file.
4. Now go back to Ansible mgmt node, do changes in /etc/ansible/hosts file to include the node you will be installing software. Make sure you add public or private IP address of target node as highlighted below in red color:
sudo vi /etc/ansible/hosts
[My_Group]
xx.xx.xx.xx ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~
5. Create a Playbook for setting up Tomcat 9
---
- hosts: My_Group
tasks:
- name: Task # 1 Update APT package manager repositories cache
become: true
apt:
update_cache: yes
- name: Task # 2 - Install Tomcat using Ansiblebecome: yes
apt:
name: "{{ packages }}"
state: present
vars:
packages:
- tomcat9
- tomcat9-examples
- tomcat9-docs
6. Execute Playbook:
No comments:
Post a Comment