DevOps Classroom Series – 20/Dec/2020

Ansible playbook structure

  • Playbooks are expressed in the form of YAML files
  • Ansible Playbook structure Refer Here
---
- name: <name of the play>
  hosts: <which hosts this playbook has to be executed>
  become: <yes/no> # This will execute with root previleges
  tasks:
    - name: <name of the task>
      <module-name>:
        <module-parameter-1>: <value-1>
        ..
        ..
        state: <value of the stated>

  • Lets write a playbook to install lamp stack on ubuntu instance Refer Here
  • Ensure Visual Studio code is installed on your machine and ansible extension is installed Preview Preview Preview
  • Refer Here for the first set of changes
  • Lets apply the playbook Preview Preview Preview
  • Ansible has executed the playbook and it executes 1 extra task (Gathering Facts)
  • Now lets try to install apache packages
sudo apt install php libapache2-mod-php php-mysql php-cli -y
  • Refer Here for the changes done
  • Execute the ansible playbook Preview
  • In the output changed represent ansible has done some execution to meet the desired state, OK means desired state is already met
  • Lets execute the same playbook again, In this case there will no changed as the desired state is met as a result of previous execution Preview
  • So when ansible is executing it is trying to maintain the state.
  • Now the next manual step is create a file, lets use copy the file from ansible control server to node Refer Here Preview Preview

Deploying a tomcat application

  • Steps:
#!/bin/bash
sudo apt-get update
sudo apt-get install openjdk-8-jdk -y
sudo apt-get install tomcat8 -y
sudo -i # become a root user
cd /var/lib/tomcat8/webapps
wget https://referenceappkhaja.s3-us-west-2.amazonaws.com/gameoflife.war
# Now navigate to http://publicip:8080/gameoflife
  • Tip: Search the following in google
apt in ansible

Preview

  • Now to download the file google Preview

  • Execute the playbook for yaml Refer Here Preview

  • We Still need to understand

    • How ansible is configured
    • How ansible is executing modules on the remote nodes
    • How can i make ansible work with different python versions.
    • Playbook optimizations
  • Exercise:

Leave a Reply

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

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

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