Ansible for Network Engineers
Inventory: From CSV to Ansible Inventory
What you'll learn
- How to translate a CSV inventory into Ansible's INI inventory format
- How to translate the same inventory into Ansible's YAML inventory format
- What groups, host variables, and group variables are for
- That this is the same 5-device fleet from every prior capstone, in a new format
Listen to a guided explanation of this lesson.
Spoken narration isn't supported in this browser.
The same fleet, one more time
Every capstone since "Your First Network Automation" has used the same five-device fleet:
hostname,ip,platform
SW1,10.10.10.1,cisco_ios
SW2,10.10.10.2,cisco_ios
SW3,10.10.10.3,cisco_ios
SW4,10.10.10.4,cisco_ios
SW5,10.10.10.5,cisco_iosThree columns: hostname, ip, platform. This lesson translates exactly this data into the two inventory formats Ansible understands — nothing about the underlying fleet changes.
Ansible doesn't read CSV directly. It reads its own inventory format — in either of two shapes: INI-style, or YAML.
INI-style inventory
[switches]
SW1 ansible_host=10.10.10.1
SW2 ansible_host=10.10.10.2
SW3 ansible_host=10.10.10.3
SW4 ansible_host=10.10.10.4
SW5 ansible_host=10.10.10.5
[switches:vars]
ansible_network_os=ios
ansible_connection=network_cli[switches] declares a group containing all five hosts. ansible_host maps each hostname to its IP — exactly devices.csv's hostname and ip columns. [switches:vars] applies shared variables to every host in the group at once, instead of repeating them per host.
platform becomes ansible_network_os — and the value itself changes too
devices.csv's platform column held Netmiko's device-type string: "cisco_ios". Ansible's own convention for the same fact is the variable ansible_network_os, and its value for Cisco IOS devices is "ios" — shorter, and specific to Ansible's own network modules. Same fact (this is a Cisco IOS device), two different tools' own naming conventions for it.
YAML inventory — the same data, Ansible's other format
switches:
hosts:
SW1:
ansible_host: 10.10.10.1
SW2:
ansible_host: 10.10.10.2
SW3:
ansible_host: 10.10.10.3
SW4:
ansible_host: 10.10.10.4
SW5:
ansible_host: 10.10.10.5
vars:
ansible_network_os: ios
ansible_connection: network_cliIdentical information to inventory.ini above — a switches group, five hosts each with an ansible_host, and shared vars for the whole group. This is real, valid YAML — worth reading closely against 'Understanding YAML for Network Automation''s indentation rules from Phase 2.5.
Reading this, not writing a parser for it
This is the same YAML-reading skill Phase 2.5 built — indentation shows nesting, a colon-and-space separates key from value. What's different here is what reads it: Ansible itself parses this file when a playbook runs. Nothing in this module writes Python code to parse it — that was a deliberate choice explained further in Lesson 4.
Groups and variables, briefly
A group (switches, here) is a named collection of hosts a playbook can target all at once, instead of listing five hostnames every time. A host variable (ansible_host) belongs to one specific host. A group variable (ansible_network_os, ansible_connection, under vars) applies to every host in the group — set once, not five times.
Key takeaways
- Ansible reads its own inventory format — INI-style or YAML — not CSV directly; devices.csv's exact data (hostname, ip, platform) translates into either.
- platform's value changes from Netmiko's 'cisco_ios' to Ansible's own 'ios' convention for ansible_network_os — same fact, different tool's naming.
- Groups let a playbook target many hosts at once; group variables apply to every host in a group; host variables override the group default for one specific host.
- This is the same 5-device fleet (SW1–SW5) from every prior capstone — only the file format describing it has changed.