1.

What is Ansible Inventory and its types?

Answer»

In Ansible, there are two types of INVENTORY files: Static and Dynamic.

  • Static inventory file is a list of managed hosts declared under a host group using EITHER hostnames or IP addresses in a plain text file. The managed host entries are listed below the group name in each LINE. For example
[gatewayed]staging1 ansible_host=10.0.2.1staging2 ansible_host=10.0.2.2
  • Dynamic inventory is GENERATED by a SCRIPT written in Python or any other programming language or by using plugins(preferable). In a cloud setup, static inventory file configuration will fail since IP addresses change once a virtual server is stopped and started again. We create a demo_aws_ec2.yaml file for the config such as
plugin: aws_ec2 regions:ap-south-1 filters:tag:tagtype: testing

Now we can fetch using this command

ansible-inventory -i demo_aws_ec2.yaml -graph


Discussion

No Comment Found