DevOps Classroom notes 02/Aug/2025

Groups in ansible inventory

  • Lets look at a simple inventory
localhost
172.31.44.74
172.31.33.52
  • We can add groups
[ubuntu]
localhost
172.31.44.74

[redhat]
172.31.33.52
  • Once the groups are added we can use group name in hosts sections
    • all refers all unique entries in the inventory
  • an entry can be present in multiple groups
[ubuntu]
localhost
172.31.44.74

[redhat]
172.31.33.52

[appservers]
172.31.44.74
172.31.33.52
  • These kind of inventories where we enter ip addresses into a file are referred as static inventories.
  • Inventories can be written in yaml as well.

Tomcat Installation using ansible

  • Initially we will configure installation on ubuntu instances
  • Manual steps
sudo apt update
sudo apt install openjdk-17-jdk -y
sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcat
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.25/bin/apache-tomcat-10.1.25.tar.gz -P /tmp
sudo mkdir /opt/tomcat
sudo tar -xvf /tmp/apache-tomcat-10.1.25.tar.gz -C /opt/tomcat --strip-components=1
sudo chown -R tomcat:tomcat /opt/tomcat
sudo chmod -R g+r /opt/tomcat/conf
sudo chmod g+x /opt/tomcat/conf
  • Now create a service file with the following contents at /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat 10 Web Application Container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom"

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target
  • Now enable and start tomcat
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl enable tomcat

Lets write a playbook

  • Lets create a yaml file for a playbook and configure it to install openjdk 17
---
- name: install tomcat 10
  hosts: appservers
  become: yes
  tasks:
    - name: update packages and install java
      ansible.builtin.apt:
        name: openjdk-17-jdk
        update_cache: yes
        state: present

  • Create a system user called as tomcat
  • Refer Here for the changes done in the playbook.
  • download and extract tomcat Refer Here for changes.
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%