Infrastructure as Code with Terraform and Ansible Basics Quiz Quiz

Explore key concepts of Infrastructure as Code (IaC), focusing on automation and configuration using Terraform and Ansible. Test your foundational knowledge about templates, provisioning, state management, syntax, and more within IaC workflows.

  1. Understanding IaC Purpose

    Which main benefit does Infrastructure as Code (IaC) provide when managing IT infrastructure?

    1. Enables repeatable and automated provisioning of resources
    2. Increases manual configuration steps
    3. Enforces hardware-only deployment
    4. Limits scalability of environments

    Explanation: IaC allows infrastructure to be provisioned automatically using code, making deployments repeatable and reducing errors. Increasing manual steps and hardware-only deployment contradict automation goals. Limiting scalability is not a benefit of IaC—automation actually supports increased scale.

  2. Terraform Code Structure

    In Terraform, which file extension is typically used for infrastructure configuration files?

    1. .ini
    2. .sh
    3. .tf
    4. .yaml

    Explanation: Terraform uses files with the .tf extension to define infrastructure resources. .yaml files are often used with other tools, but not Terraform. .sh is for shell scripts, while .ini is used for configuration in some legacy systems.

  3. Ansible Inventory

    What is the primary purpose of an inventory file in Ansible?

    1. Compile custom modules
    2. Define lists of target hosts or groups
    3. Track usage billing
    4. Store log output of deployments

    Explanation: An inventory file in Ansible outlines which hosts or groups tasks are applied to. It does not store logs, compile modules, or handle billing. These distractors relate to other aspects of system administration, but not to Ansible's inventory function.

  4. State Management in Terraform

    Why does Terraform maintain a 'state' file during infrastructure management?

    1. For storing variables temporarily
    2. To store the current known state of resources
    3. For debugging script syntax
    4. To list available modules

    Explanation: Terraform's state file keeps track of the resources it manages and their attributes. Temporary storage of variables is handled within code, not the state file. Debugging and module listing are separate features unrelated to state.

  5. Ansible Playbook Language

    Which language format is primarily used to write Ansible Playbooks?

    1. JSON
    2. YAML
    3. Python
    4. XML

    Explanation: Ansible playbooks are written in YAML format, which is both human-readable and easy for automation tools to interpret. While Ansible is implemented in Python, and JSON/XML are used in other contexts, playbooks specifically require YAML.

  6. Terraform Plan Command

    What does running the 'plan' command in Terraform accomplish before applying changes?

    1. Monitors disk usage
    2. Deletes resources irreversibly
    3. Shows a preview of proposed infrastructure changes
    4. Automatically applies all changes

    Explanation: The 'plan' command in Terraform previews upcoming changes, allowing you to review them before applying. It does not apply or delete resources directly, and is not used for disk monitoring. Only the correct option matches the plan command's function.

  7. Ansible Modules Function

    What role do modules play when running an Ansible playbook?

    1. Monitor CPU temperature
    2. Encrypt output files for security
    3. Provide additional hardware for playbooks
    4. Define and perform specific tasks or operations

    Explanation: Modules in Ansible represent reusable units that perform tasks from simple operations to complex system configuration. They do not provide hardware, encrypt files by default, or manage hardware monitoring like CPU temperature.

  8. Variables Scope in Terraform

    How can Terraform variables be set when running a configuration?

    1. Directly in the OS kernel
    2. Through a variables file, environment variables, or command line arguments
    3. They cannot be set by a user
    4. Only within the main resource file

    Explanation: Variables in Terraform are flexible and can be set in multiple ways, including files, environment variables, or directly through the command line. They are not restricted to the main resource file or OS kernel, nor are they inaccessible for user configuration.

  9. Idempotence in IaC Tools

    What does it mean if an IaC tool like Ansible is idempotent?

    1. Changes are applied multiple times and always result in different states
    2. Applying the same code repeatedly will not change the system after the first run
    3. Script execution always fails
    4. Resources are duplicated each run

    Explanation: Idempotence ensures that repeating an operation leads to the same result, which is essential for reliable configuration management. Other options incorrectly describe randomness, duplication, or failure, which are not attributes of idempotence.

  10. Setting Up Hosts with Ansible

    If you want to install a package on multiple servers using Ansible, what would you primarily use?

    1. Ansible playbook targeting a group of hosts in the inventory
    2. A shell script unrelated to Ansible
    3. Changing the state file manually
    4. Manual installation on each server

    Explanation: Ansible playbooks automate tasks such as package installation by targeting hosts or host groups in the inventory. Manual installs and unrelated scripts do not utilize Ansible's automation. Editing the state file manually is not how tasks are applied in Ansible.