Cisco CCNA (200-301)Automation and ProgrammabilityMedium

An engineer creates an Ansible inventory file named 'hosts.ini' with the following content: [switches] sw1 ansible_host=10.1.1.1 sw2 ansible_host=10.1.1.2 [routers] r1 ansible_host=10.1.1.10 What is the purpose of the group names '[switches]' and '[routers]' in this file?

  1. AThey specify the SSH port used to connect to each device
  2. BThey define the order in which Ansible modules execute
  3. CThey define variable data types used in the playbook
  4. DThey organize managed hosts into logical groups that playbooks can target
Show answer & explanation

Correct answer: D. They organize managed hosts into logical groups that playbooks can target

In an Ansible inventory file, bracketed names like [switches] and [routers] define host groups. Playbooks can then target a specific group (e.g., 'hosts: switches') so tasks apply only to the devices in that group, simplifying management of different device types.

Why the other options are wrong

  • A. SSH port is set with a variable like ansible_port, not the group header.
  • B. Module execution order is defined by tasks in the playbook, not inventory groups.
  • C. Group names do not define variable types; they classify hosts.

Ansible Inventory Groups

Named collections of hosts in an Ansible inventory file, defined using square brackets, that allow playbooks to target specific sets of devices.

  • Defined with [group_name] syntax
  • Playbooks reference groups via the 'hosts:' key
  • A host can belong to multiple groups

Memory trick: Brackets build buckets — sort devices into groups.

More Automation and Programmability questions