Categories

Category cover

Automation
155 posts

Category cover

Learning paths
119 posts

Category cover

CISO
22 posts

Category cover

Security
20 posts

Category cover

Notes
19 posts

Category cover

Personal Security
18 posts

Category cover

Infrastructure
12 posts

Category cover

OT/ICS
5 posts

Category cover

Books
3 posts

Category cover

UNetLab
3 posts

Category cover

Write-up
3 posts

Category cover

OSInt
2 posts

Category cover

My life
1 posts

Ansible inventory

Andrea Dainese
August 02, 2024
Post cover

The inventory is the source of truth containing the information that Ansible will use to connect to devices. The inventory also allows defining variables at the host or group level. Particularly, variables can be used, in advanced scenarios, to define all infrastructure parameters, such as interfaces, IP addresses, router ID, etc.

Ansible supports both static and dynamic inventories. The static inventory is defined by a file in INI or YAML format, while the dynamic inventory is an executable that prints JSON to standard output.

We must also pay attention to selecting the correct protocol  for communication with remote devices and the correct platform  based on the device. In the upcoming examples, we will connect to Cisco IOS devices, which require executing commands via an SSH connection. In this regard, we need to set:

  • ansible_connection: network_cli, indicating that we will use CLI over an SSH channel;
  • ansible_network_os: ios, indicating that we will use the module written for Cisco IOS devices.

Initially, we assume that we can log in with a privileged user. We will address how to manage non-privileged users later.

Static Inventory in INI Format

The static inventory in INI format has the following structure:

All devices should be part of group all then he can be inserted into additional groups. We can also define host level or group level vars.

Continue reading the post on Patreon .