50 Ansible Inventory Interview Questions and Answers (Beginner to Advanced) – 2026 Guide
Prepare for your Ansible and DevOps interviews with these carefully selected Ansible inventory basic to advance MCQs. This set covers core Ansible Vault. Each question includes clear answers and explanations to help you strengthen your understanding and boost interview confidence.
By the end of this article, you’ll be well-equipped to handle a variety of Ansible Inventory interview questions and demonstrate your proficiency in automating IT tasks efficiently and effectively.
1. What is the primary purpose of an Ansible inventory ?
A) To write the logic for application deployment
B) To define and list the managed nodes or hosts Ansible will manage
C) To store the Ansible source code
D) To encrypt sensitive playbook variables
Correct Answer: B
Explanation: An inventory is essentially a “contact list” for your computers, telling Ansible which machines to work on and how to group them. It acts as the bridge between the control node and the managed hosts.
2. Where is the default location for the Ansible inventory file ?
A) /etc/ansible/playbooks
B) /etc/ansible/hosts
C) /usr/bin/ansible/inventory
D) /home/.ansible/hosts
Correct Answer: B
Explanation: By default, Ansible looks for its host list at /etc/ansible/hosts. However, most users prefer creating separate inventory files for different projects to keep them organized.
3. Which flag is used to specify a custom inventory file during command execution ?
A) -c
B) -l
C) -i
D) -f
Correct Answer: C
Explanation: The -i flag (short for inventory) allows you to point Ansible to the specific path of your custom inventory file. This is a best practice to avoid running commands on the wrong set of servers.
4. What are the two most common file formats for Ansible inventories ?
A) INI and YAML
B) XML and HTML
C) JSON and TXT
D) CSV and PDF
Correct Answer: A
Explanation: While the classic INI format is widely used for its simplicity, YAML has become the community standard for modern, complex projects. Both formats allow you to define hosts, groups, and variables.
5. Which Ansible command is used to view the inventory structure in JSON or graph format ?
A) ansible-inventory-list
B) ansible-check-inventory
C) ansible-config
D) ansible-inventory
Correct Answer: D
Explanation: The ansible-inventory command is a tool used to validate and understand your inventory setup. It can display the inventory as a list or a visual graph to show group nesting.
6. What is a “Static Inventory” ?
A) A manually maintained text file containing fixed lists of hosts
B) A list of hosts generated automatically by a cloud plugin
C) An inventory that changes every time a server is restarted
D) A list of hosts stored only in the system’s memory
Correct Answer: A
Explanation: A static inventory is a simple file where hosts and groups are explicitly listed by the user. It is ideal for small, stable environments like on-premise data centers.
7. When is a “Dynamic Inventory” preferred over a static one ?
A) When you have only two or three servers
B) When you don’t have an internet connection
C) When managing cloud-based infrastructure that changes frequently
D) When you want to avoid using YAML
Correct Answer: C
Explanation: Dynamic inventories use scripts or plugins to fetch host data from external sources like AWS, Azure, or GCP in real-time. This ensures that newly created or destroyed cloud instances are automatically tracked without manual updates.
8. In an INI inventory, how are host groups defined ?
A) Inside curly braces {}
B) Inside square brackets []
C) Using the group: keyword
D) Using indentation only
Correct Answer: B
Explanation: In the INI format, group names are specified between brackets, such as [webservers]. All hosts listed below that header belong to that group until another header is found.
9. What is the purpose of the all group in Ansible ?
A) It contains only the servers currently online
B) It only includes hosts that are not part of any other group
C) It is used to store sensitive passwords
D) It is a default group that targets every host in the inventory
Correct Answer: D
Explanation: Every inventory automatically includes an all group, which includes every managed node listed in the file. This allows you to run a single task across your entire infrastructure easily.
10. Which default group contains hosts that do not belong to any user-defined group ?
A) orphans
B) ungrouped
C) misfits
D) independent
Correct Answer: B
Explanation: The ungrouped group is a built-in category for hosts that are listed in the inventory but haven’t been assigned to a specific group. This group is created automatically by Ansible.
11. How do you define a subgroup (nested group) in a YAML inventory ?
A) Use the :children suffix
B) Use the subgroup: keyword
C) Nest the group names under the children: key
D) Nesting groups is not possible in YAML
Correct Answer: C
Explanation: YAML inventories use the children: key to define subgroups, creating a hierarchical structure. This allows a parent group to manage multiple child groups simultaneously.
12. What does the ansible_host variable define ?
A) The name of the Ansible control node
B) The IP address or hostname used to connect to the managed node
C) The username for the SSH connection
D) The location of the inventory file
Correct Answer: B
Explanation: The ansible_host variable allows you to assign an alias to a server in the inventory while specifying its actual network address for the connection.
13. Which variable is used to set a specific SSH port for a host in the inventory ?
A) ansible_port
B) ssh_port
C) connection_port
D) port_number3
Correct Answer: A
Explanation: You can specify a custom SSH port for individual hosts or groups by setting the ansible_port variable. This is useful when servers use non-standard ports for security.
14. What is the best practice for storing sensitive data like API keys for hosts ?
A) Put them in plain text in the inventory file
B) Hardcode them directly into the playbooks
C) Save them in the .bash_history file
D) Use Ansible Vault to encrypt the variables
Correct Answer: D
Explanation: Sensitive data should never be stored in plain text. Ansible Vault allows you to encrypt files containing secrets, which can then be safely referenced in inventories or playbooks.
15. How can you apply a variable to every host within a specific group ?
A) By defining it in the all group
B) By using group variables (e.g., in a group_vars folder)
C) By typing it next to every host name individually
D) Variables can only be applied to individual hosts
Correct Answer: B
Explanation: Group variables allow you to set common parameters for multiple hosts at once. The best practice is to store these in a group_vars directory with a file name matching the group name.
16. Between host variables and group variables, which one has higher precedence ?
A) Group variables
B) Host variables.
C) They have the same priority
D) It depends on the order they appear in the file
Correct Answer: B
Explanation: Ansible merges variables from various sources, but host-specific variables always override group-level variables. This allows you to set general group rules and then create exceptions for specific servers.
17. What command displays the inventory as a visual tree structure ?
A) ansible-inventory –tree
B) ansible-inventory –list –yaml
C) ansible-inventory –graph
D) ansible-config –view-inventory
Correct Answer: C
Explanation: The –graph option provides a visual representation of how hosts are nested within groups. This is helpful for troubleshooting complex hierarchies in large environments.
18. What is the recommended way to manage dynamic inventory in modern Ansible (version 2.8+) ?
A) Python scripts
B) Bash scripts
C) Inventory plugins
D) Manual text updates
Correct Answer: C
Explanation: While legacy scripts are still supported, inventory plugins are the recommended modern method because they are highly configurable and integrated into Ansible core.
19. Which plugin would you use to auto-discover EC2 instances in AWS ?
A) amazon.aws.aws_ec2
B) aws_cloud_auto
C) ec2_dynamic_script
D) aws_inventory_plugin
Correct Answer: A
Explanation: The aws_ec2 plugin is part of the amazon.aws collection and is used to dynamically fetch host lists from Amazon Web Services.
20. What file format do modern inventory plugins use for their configuration ?
A) YAML
B) INI
C) JSON
D) XML
Correct Answer: A
Explanation: Modern inventory plugins are configured using a YAML file that defines parameters like regions, filters, and keyed groups.
21. In an inventory, what is a “Child Group” ?
A) A group that is newly created
B) A group nested inside a parent group
C) A group with only one host
D) A group that cannot have its own variables
Correct Answer: B
Explanation: Child groups are subgroups that inherit variables from their parent group. For example, a production parent group might contain webservers and databases as its children.
22. How do you define a range of hosts (e.g., host01 to host10) without listing them individually ?
A) host[01:10].example.com
B) host.example.com
C) host{01..10}.example.com
D) host01-host10.example.com
Correct Answer: A
Explanation: Ansible supports range functionality using square brackets and a colon, which saves time when defining many hosts with a similar naming pattern.
23. What is the result of the command ansible all -m ping -i my_inventory ?
A) It deletes the inventory file
B) It installs the ping software on all servers
C) It sends an ICMP echo request to every server
D) It tests the connectivity to all hosts in the specified inventory
Correct Answer: D
Explanation: This ad-hoc command uses the ping module to log into the remote hosts and verify that Ansible can communicate with them. If successful, it returns a “pong” response.
24. Which variable can be used to set the private key file for SSH authentication for a host ?
A) key_file_path
B) ssh_identity_key
C) ansible_ssh_private_key_file
D) private_key
Correct Answer: C
Explanation: You can specify which private key Ansible should use for a specific host by setting this variable in the inventory.
25. If you want to run a playbook against a subset of hosts (e.g., only webservers), where do you define this target ?
A) In the ansible.cfg file
B) In the hosts: field of the playbook
C) Only at the command line using -i
D) Inside the vars: section
Correct Answer: B
Explanation: Every playbook has a hosts: field where you specify which group or individual host from the inventory should be targeted for those tasks.
26. What happens if Ansible cannot resolve a hostname listed in the inventory ?
A) It results in a connection failure or “UNREACHABLE” error
B) It skips the host and continues silently
C) It automatically adds the host to the local /etc/hosts file
D) It reboots the control node
Correct Answer: A
Explanation: Incorrect DNS settings or invalid hostnames in the inventory will cause host resolution failures, preventing the playbook from running on those nodes.
27. What is the benefit of using “Keyed Groups” in dynamic inventories ?
A) They prevent unauthorized access
B) They automatically create groups based on host attributes like cloud tags
C) They encrypt the host list
D) They reduce the size of the inventory file
Correct Answer: B
Explanation: Keyed groups allow you to organize cloud instances into Ansible groups automatically based on metadata like region, instance type, or custom tags.
28. How can you combine multiple inventory sources (e.g., cloud and on-premise) for a single run ?
A) It is impossible to use two sources at once
B) Use a symbolic link to join the files
C) Copy all files into /etc/ansible/hosts
D) Specify the -i flag multiple times or point to a directory containing all sources
Correct Answer: D
Explanation: Ansible can aggregate host data from multiple sources by pointing it to a directory or using the -i flag repeatedly in the command.
29. Which pattern targets hosts that are in BOTH the ‘webservers’ and ‘production’ groups ?
A) webservers:production
B) webservers+production
C) webservers:&production
D) webservers AND production
Correct Answer: C
Explanation: The ampersand (&) is used in patterns to target the intersection of two groups.
30. Which pattern targets hosts in the ‘webservers’ group but NOT in ‘staging’ ?
A) webservers:NOT:staging
B) webservers-staging
C) webservers:!staging
D) webservers:^staging
Correct Answer: C
Explanation: The exclamation mark (!) acts as a “NOT” operator in Ansible patterns to exclude certain hosts or groups.
31. What is the “Inventory Plugin” host_list used for ?
A) To list all groups in the terminal
B) To parse a comma-separated list of hosts passed directly via the command line
C) To generate a CSV file of all hosts
D) To find hosts based on their IP address only
Correct Answer: B
Explanation: The host_list plugin allows Ansible to recognize a simple string of hostnames as an inventory if you don’t want to use a file.
32. In a large environment, how can “Fact Caching” improve inventory performance ?
A) It deletes unused host records
B) It stores gathered host data between runs so it doesn’t have to be re-fetched every time
C) It increases the number of parallel tasks
D) It compresses the inventory file
Correct Answer: B
Explanation: Fact caching enables Ansible to store information about hosts (like their OS or IP) in backends like Redis or JSON files, speeding up subsequent playbook runs.
33. Where should you store host_vars and group_vars for a specific project ?
A) In the same directory as your inventory file
B) In the /tmp directory
C) Only inside the playbook YAML file
D) In the user’s home directory
Correct Answer: A
Explanation: To keep your automation modular and organized, variables should be stored in folders named host_vars and group_vars located in the same directory as the inventory file.
34. What is the “UUID” recommendation when managing multiple inventory sources ?
A) Use it to password-protect the inventory
B) Leverage it to ensure unique host records when pulling data from different platforms
C) It is used to identify the version of Ansible being used
D) Use it as a variable for the SSH port
Correct Answer: B
Explanation: When pulling hosts from various cloud and on-premise sources, using a UUID helps prevent duplicate or overlapping host records.
35. What does the inventory_hostname variable represent ?
A) The name of the current host as it is defined in the inventory file
B) The hostname of the control node
C) The IP address of the managed node
D) The name of the group the host belongs to
Correct Answer: A
Explanation: inventory_hostname is a special variable that holds the name you gave to a specific server in your inventory list.
36. Which file is used to enable or whitelist specific inventory plugins ?
A) inventory.ini
B) plugins.yml
C) ansible.cfg
D) site.yml
Correct Answer: C
Explanation: The ansible.cfg file contains an [inventory] section where you can specify which plugins (like aws_ec2 or yaml) are enabled and in what order they should run.
37. What is the benefit of using “Symbolic Links” in an inventory repository ?
A) They make the inventory run faster
B) They allow sharing variable files across multiple platforms without duplicating them
C) They encrypt the host list
D) They are required for dynamic inventories
Correct Answer: B
Explanation: Symbolic links allow you to maintain one single source of truth for shared variables that apply to different environments or platforms.
38. Which keyword is used to execute a task on a host other than the one currently targeted by the play ?
A) delegate_to
B) jump_to
C) run_on
D) proxy_to
Correct Answer: A
Explanation: delegate_to allows you to perform an action on a specific host, such as a load balancer or DNS server, while the play is actually managing web servers.
39. How do you specify the SSH user for a group of hosts in an INI file ?
A) [groupname:user=admin]
B) groupname:user:admin
C) [groupname:vars] followed by ansible_user=admin
D) [user:groupname]
Correct Answer: C
Explanation: In INI format, group-level variables are defined under a section header with the suffix :vars.
40. What does the “inventory plugin” do if it fails to understand a file ?
A) It stops Ansible immediately with an error
B) It fails and Ansible tries the next plugin in the enabled list
C) It deletes the file
D) It renames the file to .failed
Correct Answer: B
Explanation: Ansible traverses the list of enabled plugins (like host_list, then script, then yaml) until one of them successfully parses the inventory.
41. Which feature provides a centralized web UI for managing Ansible inventories at an enterprise level ?
A) Ansible Tower / Automation Platform
B) Ansible CLI
C) Ansible Galaxy
D) Ansible Vault
Correct Answer: A
Explanation: Ansible Tower (now part of the Automation Platform) provides a dashboard for managing inventories, credentials, and role-based access control.
42. How does a dynamic inventory script differ from a plugin ?
A) Scripts are modern, plugins are legacy
B) Scripts are standalone programs that return JSON; plugins are native Ansible code
C) Scripts only work with Windows
D) Plugins require an internet connection, scripts do not
Correct Answer: B
Explanation: Inventory scripts are older-style programs (often Python) that simply output a JSON structure. Plugins are the newer, recommended way to handle dynamic host discovery.
43. What is the “Jump Host” (or Proxy Host) used for in an inventory setup ?
A) To speed up the playbook run
B) To automatically create new VMs
C) To store backup copies of playbooks
D) To access target servers that are not directly reachable from the control node
Correct Answer: D
Explanation: A jump host acts as a gateway or intermediary server to provide secure access to servers in restricted networks.
44. Which variable is used to configure a Jump Host for a group of servers ?
A) ansible_gateway
B) jump_host_path
C) ansible_ssh_common_args
D) proxy_command
Correct Answer: C
Explanation: You can set the ProxyJump option within the ansible_ssh_common_args variable to route your connection through a jump server.
45. What is the purpose of the ansible_distribution fact in an inventory ?
A) It lists the number of hosts in the inventory
B) It identifies the operating system (e.g., Ubuntu, CentOS) of the managed node
C) It shows how many groups a host belongs to
D) It tracks the geographic location of the server
Correct Answer: B
Explanation: This fact is automatically gathered by Ansible and can be used in the inventory or playbooks to apply different settings based on the OS.
46. Can a single host belong to more than one group ?
A) No, it must belong to exactly one group
B) Only if it is a dynamic host
C) Only if it is in the all group
D) Yes, a host can be part of multiple groups based on function, location, etc.
Correct Answer: D
Explanation: Hosts are often categorized by “What, Where, and When,” meaning a server could be in the webservers, staging, and europe groups simultaneously.
47. What does a “Recap” at the end of a playbook run show regarding the inventory ?
A) The total number of lines in the inventory file
B) The size of the inventory file in KB
C) Which hosts were successful, changed, or failed during the run
D) The names of the groups that were skipped
Correct Answer: C
Explanation: The recap provides a summary of the execution status for every host that was targeted by the playbook.
48. Why is it recommended to separate inventory files for ‘Production’ and ‘Staging’ ?
A) To make the files smaller
B) To prevent accidental execution of commands on the wrong environment
C) Because YAML cannot handle both at once
D) Because Ansible only allows one group per file
Correct Answer: B
Explanation: Isolating environments into different files or directories is a critical safety practice to avoid damaging live production systems while testing.
49. What is the ec2.ini file used for ?
A) To configure filters and settings for the legacy AWS dynamic inventory script
B) To define static AWS hosts
C) To store AWS passwords in plain text
D) It is the main Ansible configuration file
Correct Answer: A
Explanation: When using older dynamic inventory scripts for AWS, the ec2.ini file defines which instances to discover and which regions to query.
50. What is an “Ad-hoc” command in the context of inventory ?
A) A quick, one-line task performed directly from the command line against specific hosts
B) A permanent change to the inventory file
C) A specialized plugin for managing hostnames
D) A way to delete the entire inventory
Correct Answer: A
Explanation: Ad-hoc commands allow you to perform simple tasks, like checking disk space or connectivity, across your inventory without writing a full playbook.
