Create a new static inventory containing managed nodes and groups.
Outcomes
Create a custom static inventory using Visual Studio Code.
Use automation content navigator to explore the Ansible Inventory.
As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.
[student@workstation ~]$ lab start implement-inventory
Instructions
From Visual Studio Code (VS Code) on the workstation machine, open the /home/student/implement-inventory directory.
Open VS Code. Click → to open the .
Click → .
Click → and then click .
If prompted, select , and then click .
Create a custom static inventory named inventory in the /home/student/implement-inventory directory.
Use the following table to organize the Ansible inventory.
Assign each managed node to multiple groups for best management, based on its operating system and the data center location.
| Managed node | Operating system | Data center |
|---|---|---|
iosxe1.lab.example.com
| Cisco IOS XE | Raleigh |
iosxe2.lab.example.com
| Cisco IOS XE | Johannesburg |
nxos.lab.example.com
| Cisco NX-OS | Raleigh |
junos.lab.example.com
| Juniper Junos | London |
arista-leaf1.lab.example.com
| Arista EOS | Johannesburg |
arista-leaf2.lab.example.com
| Arista EOS | Raleigh |
arista-leaf3.lab.example.com
| Arista EOS | London |
Click → .
Enter inventory as the file name, and then click .
Click in the window behind VS Code.
The window closes after the inventory file is created.
Edit the Ansible inventory file so that it contains the following content, and then click → :
[ios] iosxe[1:2].lab.example.com [nxos] nxos.lab.example.com [junos] junos.lab.example.com [eos] arista-leaf[1:3].lab.example.com [raleigh] iosxe1.lab.example.com nxos.lab.example.com arista-leaf2.lab.example.com [johannesburg] iosxe2.lab.example.com arista-leaf1.lab.example.com [london] junos.lab.example.com arista-leaf3.lab.example.com
Explore the Ansible inventory by using the ansible-navigator command in stdout mode.
Create an inventory graph of all the Ansible inventory.
In VS Code, click → .
Run the ansible-navigator inventory -m stdout --graph command to obtain the graph of all the Ansible inventory.
[student@workstation implement-inventory]$ansible-navigator inventory \-m stdout --graph@all: |--@ungrouped: |--@ios: | |--iosxe1.lab.example.com | |--iosxe2.lab.example.com |--@nxos: | |--nxos.lab.example.com |--@junos: | |--junos.lab.example.com |--@eos: | |--arista-leaf1.lab.example.com | |--arista-leaf2.lab.example.com | |--arista-leaf3.lab.example.com |--@raleigh: | |--iosxe1.lab.example.com | |--nxos.lab.example.com | |--arista-leaf2.lab.example.com |--@johannesburg: | |--iosxe2.lab.example.com | |--arista-leaf1.lab.example.com |--@london: | |--junos.lab.example.com | |--arista-leaf3.lab.example.com
Use the following table to define group variables in the Ansible inventory.
Create the network_devices group that includes the ios, nxos, junos, and eos groups.
Use VS Code to modify the Ansible inventory.
| Managed node | Network platform | Network device |
|---|---|---|
iosxe1.lab.example.com
|
cisco.ios.ios
| Yes |
iosxe2.lab.example.com
|
cisco.ios.ios
| Yes |
nxos.lab.example.com
|
cisco.nxos.nxos
| Yes |
junos.lab.example.com
|
junipernetworks.junos.junos
| Yes |
arista-leaf1.lab.example.com
|
arista.eos.eos
| Yes |
arista-leaf2.lab.example.com
|
arista.eos.eos
| Yes |
arista-leaf3.lab.example.com
|
arista.eos.eos
| Yes |
Edit the Ansible inventory file to append the following content to the inventory file, and then click → :
[network_devices:children] ios nxos junos eos [network_devices:vars] ansible_connection=ansible.netcommon.network_cli [ios:vars] ansible_network_os=cisco.ios.ios [nxos:vars] ansible_network_os=cisco.nxos.nxos [junos:vars] ansible_network_os=junipernetworks.junos.junos [eos:vars] ansible_network_os=arista.eos.eos
Select → .
Run automation content navigator in interactive mode in the VS Code terminal.
Explore the managed nodes entries in the inventory file and obtain the detail for the arista-leaf3.lab.example.com node.
Run the ansible-navigator inventory command in the VS Code terminal.
![]() |
Type 1 in the main Ansible inventory page to list the managed nodes.
![]() |
Type 2 to obtain inventory information about the arista-leaf3.lab.example.com node.
![]() |
Inventory information for the arista-leaf3.lab.example.com managed node
Type :q and then press Enter to exit the ansible-navigator command.
From VS Code, click → to close the /home/student/implement-inventory directory.