Shashikant shah

Thursday, 15 October 2020

What is ansible Inventory and types part-2

 Ansible Inventory.

Inventory contains a list of hostname or IP addresses and follows INI format. There is two type of inventory.

  •    Static inventory.
  •     Dynamic inventory.

1. Static details :-

Ansible, a static inventory file is a plain text file that contains a list of managed hosts declared under a host group using either hostnames or IP addresses.



Default path :- /etc/ansible/hosts

command line using the -i <path> option

[webservers]  

foo.example.com  

bar.example.com  

  

[dbservers]  

one.example.com:22 

two.example.com  

three.example.com 


[southeast: children]  

  Webservers

  Dbservers

 

[devops]

server[1:9]

 

[password]

server3 ansible_ssh_user=shashi ansible_ssh_pass=redhat

202.54.1.5  ansible_ssh_private_key_file=~/.ssh/Lightsail-us-west-2.pem


2.Dynamic details :-

especially a cloud setup such as AWS where the inventory file keeps constantly changing as you add or decommission servers, keeping tabs on the hosts defined in the inventory file becomes a real challenge. It becomes inconvenient going back to the host file and updating the list of hosts with their IP addresses.

1.    Create a Role for ansible permissions

create role --> aws service --> EC2 --> AmazonEC2FullAccess --> tags (ansible_full_Access)--> ok

ec2 ansible instance --> instance settings --> attach/Replace IAM Role --> ansible_full_Access --> ok

# wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.py

# wget https://raw.githubusercontent.com/ansible/ansible/stable-2.9/contrib/inventory/ec2.ini

# chmod +x ec2.ini ec2.py

# vim ec2.py

!/usr/bin/env python3

# ./ec2.py

Error :- ERROR: "Forbidden", while: getting ElastiCache clusters

solution :-

# vim  ec2.ini  

uncommit

elasticache = False

pip3 install boto

# ./ec2.py















# ansible -i ec2.py ec2 -m ping

# ansible -i ec2.py us-east-1e -m ping






No comments:

Post a Comment