Inventories
- In Ansible inventories are list of nodes
- Inventories can be static or dynamic
- Inventories can be written in two formats in static
- INI
- YAML
- Inventory orderding: A new play level keyword called as order is added which supports the following values
- inventory: This is default. It simply means Ansible will execute the order in the way they are written in inventory
- reverse_inventory
- sorted: hosts are alphabetically sorted
- reverse_sorted: hosts are reverse alphabetically sorted
- shuffle
INI
- In Inventories entries can be grouped together
[group1]
10.100.100.101
10.200.10.101
[group2]
192.168.10.11
192.168.11.11
[group3]
10.200.10.101
192.168.11.11
[group4:children]
group1
group2
- In any inventory ansible will have two default groups
- all: This is list of the nodes (unique)
- ungrouped: This is list of the nodes which donot belong to any group.
Ansible Inventory Scenarios
-
Scenario-1:
- Install utility Softwares like git, tree and nano on all machines
- manual steps:
- ubuntu
sudo apt install git tree nano -y
- rhel
sudo yum install git tree nano -y
- ubuntu
- In ansible we have a generic package module Refer Here.
- Refer Here for the changes
- manual steps:
- Install apache on centos
- manual steps:
sudo yum install httpd sudo systemctl enable httpd sudo systemctl start httpd
- Refer Here for the changeset
- Install java on ubuntu
- Refer Here for the changeset
- Install utility Softwares like git, tree and nano on all machines
-
As of now we have two nodes
- node-1: ubuntu
- node-2: centos
-
Scenario 2: Install Lamp stack on webservers. In web servers we have ubuntu and centos nodes. Try Creating one playbook for this.
- ubuntu: manual steps
- sudo apt update
- sudo apt install apache2 -y
- sudo apt install php libapache2-mod-php php-mysql php-cli -y
- echo "<?php phpinfo(); ?>" > /var/www/html/info.php
- centos: manual steps
- sudo yum install httpd -y
- sudo systemctl enable httpd.service
- sudo systemctl start httpd.service
- sudo yum install php php-mysql php-fpm -y
- echo "<?php phpinfo(); ?>" > /var/www/html/info.php
- ubuntu: manual steps