In this exercise, you will create a static inventory that uses YAML format.
Outcomes
You should be able to:
Open a terminal window on the workstation VM.
Convert the INI format static inventory file that was created in the guided exercise into one that uses the YAML format.
The following is the ~/inventory file that was created in the guided exercise.
If it does not already exist, create it now.
[leafs] leaf[01:02] [spines] spine[01:02] [cloud-services] cs01 [ios:children] cloud-services [vyos:children] spines leafs [network:children] vyos ios [servers] server[01:03]
Using that inventory file, the ansible-inventory -i inventory --graph command produces this output:
[student@workstation ~]$ansible-inventory -i inventory --graph@all: |--@network: | |--@ios: | | |--@cloud-services: | | | |--cs01 | |--@vyos: | | |--@leafs: | | | |--leaf01 | | | |--leaf02 | | |--@spines: | | | |--spine01 | | | |--spine02 |--@servers: | |--server01 | |--server02 | |--server03 |--@ungrouped:
Create a hosts inventory file named inventory.yml containing this text:
servers:
hosts:
server[01:03]
spines:
hosts:
spine[01:02]
leafs:
hosts:
leaf[01:02]
cloud-services:
hosts:
cs01
ios:
children:
cloud-services:
vyos:
children:
spines:
leafs:
network:
children:
vyos:
ios:Validate the inventory you created.
Use the ansible-inventory command with the INI format inventory file to generate a graph.
Redirect the output to a file named ini-inventory-graph.out.
[student@workstation proj]$ansible-inventory -i inventory \>--graph > ini-inventory-graph.out
Repeat the same command, this time with the YAML format inventory file.
Redirect the output to a file named yml-inventory-graph.out.
[student@workstation proj]$ansible-inventory -i inventory.yml \>--graph > yml-inventory-graph.out
Use the sdiff tool to compare the two files side by side.
[student@workstation proj]$sdiff -w 60 ini-inventory-graph.out yml-inventory-graph.out@all: @all: |--@network: |--@network: | |--@ios: | |--@ios: | | |--@cloud-services: | | |--@cloud-services: | | | |--cs01 | | | |--cs01 | |--@vyos: | |--@vyos: | | |--@leafs: | | |--@leafs: | | | |--leaf01 | | | |--leaf01 | | | |--leaf02 | | | |--leaf02 | | |--@spines: | | |--@spines: | | | |--spine01 | | | |--spine01 | | | |--spine02 | | | |--spine02 |--@servers: |--@servers: | |--server01 | |--server01 | |--server02 | |--server02 | |--server03 | |--server03 |--@ungrouped: |--@ungrouped:
This concludes the guided exercise.