Sobes.tech
Junior — Middle

Can you explain what Inventory in Ansible is and how it is used to manage hosts?

sobes.tech AI

Answer from AI

Inventory in Ansible is a file or set of files that describe managed hosts and their groups. Inventory serves to organize and classify servers on which playbooks and tasks will be applied.

Main features of Inventory:

  • Grouping hosts by roles or environments (e.g., webservers, dbservers).
  • Defining variables for groups or individual hosts.
  • Support for various formats: INI, YAML, dynamic scripts.

Example of a simple INI inventory:

[webservers]
web1.example.com
web2.example.com

[dbservers]
db1.example.com

[webservers:vars]
ansible_user=deploy

In this example, two groups of hosts with different servers are specified, as well as the variable ansible_user, which applies to all web servers.

Inventory allows Ansible to know where and how to connect for automation.