Ansible Contd….
- Lets try to install tomcat 10 on ubuntu 22.04 Refer Here
- Ansible WOW (Ways of Working)
- Ensure your manual steps are working
- For each step try to find a module which can help expressing desired state.
- Manual Steps
sudo apt update
sudo apt install openjdk-11-jdk -y
java -version
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
VERSION=10.1.4
wget https://www-eu.apache.org/dist/tomcat/tomcat-10/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz -P /tmp
sudo tar -xf /tmp/apache-tomcat-${VERSION}.tar.gz -C /opt/tomcat/
sudo ln -s /opt/tomcat/apache-tomcat-${VERSION} /opt/tomcat/latest
sudo chown -R tomcat: /opt/tomcat
sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'
sudo nano /etc/systemd/system/tomcat.service
sudo systemctl daemon-reload
sudo systemctl enable --now tomcat
sudo systemctl status tomcat
- Now for web interface follow the docs Refer Here

Ansible Playbook to automate the above steps
- Refer Here for the changes done to install java
- Ensure syntax is correct
ansible-playbook -i hosts --syntax-check tomcat.yml - Execute the playbook

- To enable verbose logging of ansible
-v to -vvvv - Now we are supposed to create a user called tomcat
- with home directory in /opt/tomcat
- with shell /bin/false
- with group tomcat (same as username)
- Module in ansible for useradd Refer Here
- Exercise: try writing the playbook to do the tomcat installation on centos Refer Here
