DevOps Classroomnotes 23/Mar/2022

Summary of Playbook So far

Preview

Inventory

  • This is all about describing your servers where the applications need to be deployed
  • Navigate to /etc/ansible and you will find two files
    • ansible.cfg
    • hosts
      Preview
  • ansible.cfg: Refer Here for sample and this file helps in configuring ansible.
  • hosts:
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers:

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group:

## [webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110

# If you have multiple hosts following a pattern, you can specify
# them like this:

## www[001:006].example.com

# Ex 3: A collection of database servers in the 'dbservers' group:

## [dbservers]
##
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57

# Here's another example of host ranges, this time there are no
# leading 0s:

## db-[99:101]-node.example.com
  • This file acts as a default inventory and will come into play when the user executes ansible or ansible-playbook commands without inventory argument.
  • The inventory file can be written in two formats
    • ini
    • yaml

ini format inventory files

  • We can create groups by using [groupname]
[ubuntu]
localhost
172.31.7.144

[redhat]
172.31.31.169

Preview
Preview
Preview
* The same inventory can be written in yaml format as well

all:
  children:
    ubuntu:
      hosts:
        localhost:
        172.31.7.144:
    redhat:
      hosts:
        172.31.31.169:
  • Now consider the following inventory
[ubuntu]
localhost
172.31.7.144

[redhat]
172.31.31.169

[appserver]
172.31.7.144
172.31.31.169

Preview
Preview
* The above inventory in yaml file

all:
  children:
    ubuntu:
      hosts:
        localhost:
        172.31.7.144:
    redhat:
      hosts:
        172.31.31.169:
    appserver:
      hosts:
        172.31.7.144:
        172.31.31.169:

  • If you directly write entries
  • INI Format
    ini
    localhost
    172.31.31.169
    172.31.7.144
  • The same stuff in yaml can be done as shown below
    yml
    all:
    hosts:
    localhost:
    172.31.7.144:
    172.31.31.169:

Lets continue refining our playbook to install java on redhat and ubuntu

  • All modules list in ansible Refer Here
  • To install java we have used apt or yum which are os package managers Refer Here for the list of all the os package managers
  • Ansible has a generic package manager Refer Here for official documentation
    Preview
  • Refer Here for the changes made by introducing variables in inventory
  • Exercise: Execute this playbook and verify the results
    Preview
  • Apply the same approach for node js installation.

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner