DevOps Classroomnotes 07/Aug/2022

Ansible Variables

  • Variables in Ansible can be declared in

    • Playbooks
    • Inventory files
    • Many other locations
  • Lets write playbook to install tomcat Refer Here

Scenario: Installing tomcat9 on ubuntu 20.04

  • Lets verify if the manual steps are working or not
  • Step -1 : install java
sudo apt update
sudo apt install openjdk-11-jdk -y
  • Refer Here for the playbook and inventory created so far.
    Preview
  • Step 2: Create a tomcat user: Refer Here for the manual steps
  • We have create a task using user module to create system user. Refer Here for the changes added.
    Preview
  • Now lets download the tomcat tar file and extract it and Refer Here for the changes done in the playbook to accomodate tomcat download and extract
    Preview
  • Now lets try to write an ansible task to create a symbolic linkm sudo ln -s /opt/tomcat/apache-tomcat-${VERSION} /opt/tomcat/latest
  • Refer Here for the changes to create symlink
    Preview
    Preview
  • This playbook is creating the latest tomcat folder with root permissions Refer Here
    Preview
  • To automate the step sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh' one approach is to use
    • ansible.builtin.command which executes the linux command
  • The problem with this approach is, it is not idempotent. So the command will be executed every time ansible playbook is executed.
  • To solve this problem,
    • We can use lookups
    • Registering varaibles

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Wordpress Development Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube