# Inventory: Hosts and Groups — Ansible: Automate Servers with Playbooks

Source: https://www.geekswithgeeks.com/en/ansible/ans-inventory

> Describe hosts, groups, group-of-groups and group variables in an INI inventory.

## Tell Ansible what exists

The **inventory** lists the hosts Ansible manages and organises them in **groups** so you can target them together (`web`, `db`, `prod`). A group can contain other groups with `:children`, and `:vars` attaches variables to a group. Inventories can be INI or YAML files, or **dynamic** scripts/plugins that read from a cloud provider. Use `ansible-inventory --graph` to see how Ansible understands yours.

## An INI inventory

`ansible_connection=local` is only for this demo. For real servers use their hostnames or IPs and SSH.

```ini
[web]
web1 ansible_connection=local
web2 ansible_connection=local

[db]
db1 ansible_connection=local

[prod:children]
web
db

[web:vars]
http_port=8080
```

## How Ansible sees it

I ran `ansible-inventory -i inventory.ini --graph` on the file above. `web` and `db` nest inside `prod`.

```bash
ansible-inventory -i inventory.ini --graph
```

Output:

```
@all:
  |--@ungrouped:
  |--@prod:
  |  |--@web:
  |  |  |--web1
  |  |  |--web2
  |  |--@db:
  |  |  |--db1
```

**Quiz:** What does `[prod:children]` do in an INI inventory?

- [ ] Encrypts the group
- [ ] Deletes the prod group
- [ ] Creates a new host called children
- [x] Makes the listed groups members of prod

*Answer:* Makes the listed groups members of prod. The :children suffix means the entries are groups nested under the parent.
