Ansible Inventory Files: Static vs Dynamic Quiz Quiz

Explore the differences between static and dynamic Ansible inventory files with this quiz designed to help you identify key concepts, use cases, and configuration basics for both types. Strengthen your understanding of managing hosts effectively in automation workflows using Ansible inventory systems.

  1. Static Inventory File Format

    Which file format is most commonly used for static Ansible inventory files when defining hosts and groups manually?

    1. XML
    2. YAML
    3. CSV
    4. INI

    Explanation: INI format is the most common for static Ansible inventory files, allowing you to define hosts and groups clearly in a simple text structure. YAML can also be used for inventories but is less common for static inventories compared to INI. CSV and XML are not standard formats for Ansible static inventory files. Using unsupported formats may prevent Ansible from reading your inventory properly.

  2. Dynamic Inventory Source

    What does a dynamic Ansible inventory typically use to obtain a list of hosts on demand?

    1. An imported Excel file
    2. A static list in a text file
    3. A hardware device
    4. A script or plugin

    Explanation: Dynamic inventories retrieve hosts by executing a script or plugin, which can query external systems or cloud providers in real-time. A static list in a text file is used only for static inventories and cannot update automatically. Using Excel files or hardware devices is not supported for obtaining dynamic hosts in Ansible.

  3. Updating Host Lists

    If your managed infrastructure changes frequently, which type of inventory is better suited to automatically reflect these changes?

    1. Offline Inventory
    2. Static Inventory
    3. Directory Inventory
    4. Dynamic Inventory

    Explanation: Dynamic inventory is designed to update host lists on demand by gathering real-time information, making it ideal for changing environments. Static inventory requires manual updates whenever infrastructure changes, which can lead to outdated records. Directory and offline inventory are not specific Ansible inventory types, and would not address frequent changes.

  4. Identifying Inventory Types

    You see an inventory file called 'hosts.ini' with manually listed IP addresses and group names. What type of inventory is this?

    1. Virtual Inventory
    2. Database Inventory
    3. Dynamic Inventory
    4. Static Inventory

    Explanation: A file called 'hosts.ini' with explicit IP addresses and groupings defines a static inventory, where entries remain until manually changed. Dynamic inventories are usually scripts or plugins, not simple text files. Virtual and database inventory are not recognized types in basic Ansible usage.

  5. Dynamic Inventory Example

    Which of the following best describes a valid dynamic inventory for Ansible?

    1. A PDF report of servers
    2. A CSV file with host entries
    3. A plain text file listing hostnames only
    4. An executable Python script that outputs JSON with host data

    Explanation: A dynamic inventory can be a Python script (or other executable) that generates JSON describing groups and hosts on demand. CSV files and plain text files are formats for static inventories and do not support on-the-fly queries. PDF files are not compatible for inventories and cannot be processed by Ansible.

  6. Host Variable Placement

    In a static inventory, where should you define variables for a particular host?

    1. Outside the inventory file
    2. Directly under the host entry
    3. Only in a separate playbook
    4. At the very top of the file

    Explanation: Variables for a host in a static inventory can be placed directly below the host entry using INI or YAML syntax. Defining variables outside the inventory file may not apply to the desired host, and variables at the top could be ignored by Ansible. Playbooks can define variables, but host-specific variables are typically given in the inventory.

  7. Inventory Source File Name

    What is the default name of the static inventory file that Ansible looks for in its working directory?

    1. machines
    2. hosts
    3. nodes
    4. inventory

    Explanation: Ansible, by default, searches for a file named 'hosts' for its static inventory unless provided a different location. 'Inventory,' 'nodes,' and 'machines' are not the default names, although they can be used if explicitly set in your configuration. Using the default 'hosts' file ensures out-of-the-box compatibility.

  8. When to Use Static Inventory

    When is it most appropriate to use a static inventory in Ansible?

    1. When integrating with cloud APIs
    2. When servers are provisioned and destroyed daily
    3. When the list of managed hosts does not change often
    4. When auto-discovery of hosts is required

    Explanation: Static inventories are ideal for stable environments where the host list remains consistent over time, reducing management effort. For frequently changing infrastructures, integrating with APIs, or automatic discovery, dynamic inventories are preferable. Static files do not support real-time updates or auto-discovery features.

  9. Running with a Custom Inventory

    Which Ansible command-line option allows you to specify a custom inventory file, whether it is static or dynamic?

    1. -d
    2. -h
    3. -c
    4. -i

    Explanation: The '-i' flag is used with Ansible commands to point to a custom inventory file or script. '-d' and '-c' have other functions, and '-h' typically displays help information. Using '-i' ensures you can switch between different inventories as needed.

  10. Output Format for Dynamic Inventory

    What output format should a dynamic inventory script return so that Ansible can correctly interpret the list of hosts and groups?

    1. TXT
    2. JSON
    3. INI
    4. CSV

    Explanation: Dynamic inventory scripts must output structured data in JSON format so Ansible can parse the hosts, groups, and variables efficiently. INI and CSV are not valid for dynamic script outputs but are for static inventories. A plain TXT file will not be recognized correctly by Ansible for dynamic usage.