$ cat hosts
[iosxe]
10.10.30.171
[iosxe:vars]
ansible_network_os=ios
ansible_connection=network_cli
The brackets are used to define group names. Groups are
used to classify hosts that share a common characteristic,
such as function, operating system, or location. In this
case, the [iosxe] group of devices contains only one
entry: the management IP address of a Cisco CSR1000v
router. The vars keyword is used to define variables. In
this example, two variables are defined for the iosxe
group. The ansible_network_os variable specifies
that the type of operating system for this group of
devices is IOS, and the ansible_connection variable
specifies that Ansible should connect to the devices in
this group by using network_cli, which means SSH.
Variables can be referenced in playbooks; as mentioned
previously, as the inventory files become larger, it is a
good idea to separate the variables’ definitions into
separate files.
The site.yml file in this example uses the
ios_command Ansible module to send two commands
to the iosxe group of devices: show version and show
ip interface brief. The YAML definition of the
playbook looks as shown in Example 15-1.
Example 15-1 Ansible Playbook Example
Click here to view code image
$ cat site.yml
---
- name: Test Ansible ios_command on Cisco IOS
XE
hosts: iosxe