---
title: "Ansible: Configuration Management & Automation"
description: "Test your knowledge of Ansible fundamentals with this comprehensive quiz covering playbooks, modules, inventory management, handlers, roles, and automation best practices."
author: "Mohammad Abu Mattar"
canonical: https://mkabumattar.com/quizzes/post/ansible-automation-fundamentals-quiz
---

# Ansible: Configuration Management & Automation

Welcome to the Ansible Basics Quiz! This quiz is designed to test your understanding of fundamental Ansible concepts, modules, and best practices. Each question is multiple-choice, and you'll find hints to help you along the way. Good luck!

## Questions

### 1. Which command is used to execute an Ansible playbook?

- `ansible-run`
  - There is no native "ansible-run" command; execution is handled by the playbook tool.
- **`ansible-playbook`** ✅
  - The "ansible-playbook" CLI tool is used to parse and execute YAML-based playbooks.
- `ansible-apply`
  - While tools like Terraform use "apply," Ansible uses the playbook command for execution.
- `ansible-execute`
  - This is not a valid Ansible command; playbooks must be run through the specific playbook tool.

**Hint:** It is a hyphenated command starting with the tool name.

### 2. What is the default file path for the Ansible inventory file?

- **`/etc/ansible/hosts`** ✅
  - By default, Ansible looks for its host definitions in the /etc/ansible/hosts file.
- `/etc/ansible/inventory`
  - While "inventory" is a common custom name, the system default file is named "hosts".
- `/var/ansible/hosts`
  - Ansible configuration and inventory files are stored in /etc, not the /var directory.
- `/usr/ansible/inventory`
  - The /usr directory is for user binaries, not configuration files like the inventory.

**Hint:** It is located in the /etc/ directory.

### 3. Which keyword defines the remote user Ansible uses for SSH connections?

- `user`
  - In modern Ansible, "user" is a module for account management, not a connection parameter.
- **`remote_user`** ✅
  - The "remote_user" keyword specifies the specific SSH user for the remote host connection.
- `login_user`
  - This is not a valid Ansible keyword; connection users must be defined as remote_user.
- `ssh_user`
  - While Ansible uses SSH, the keyword for the connection identity is "remote_user".

**Hint:** It is often set at the play level.

### 4. What is the primary purpose of the "become: yes" directive?

- Enable remote logging
  - Logging is handled by the ansible.cfg file or connection-specific parameters.
- **Enable privilege escalation** ✅
  - The "become" directive allows tasks to run with root or other administrative privileges.
- Enable SSH key sharing
  - Key sharing is managed by the SSH agent or specific connection variables.
- Enable multi-user access
  - This directive handles permission levels for a single user, not multi-user session management.

**Hint:** Think of the "sudo" command in Linux.

### 5. Which module is recommended for installing packages on RHEL-based systems?

- `apt`
  - The "apt" module is specifically used for Debian and Ubuntu-based package management.
- **`dnf`** ✅
  - The "dnf" module is the modern package manager for RHEL, Fedora, and CentOS systems.
- `pkg`
  - While "pkg" is a generic wrapper, "dnf" is the specific module for Red Hat-based systems.
- `rpm`
  - The "rpm" module is for low-level package handling, not high-level dependency management.

**Hint:** It is the successor to the "yum" module.

### 6. In Ansible, what is a "Fact"?

- A hard-coded variable
  - Hard-coded values are simply "variables"; facts are discovered dynamically during execution.
- **System information gathered** ✅
  - Facts are pieces of host-specific information discovered by the setup module at runtime.
- A task failure message
  - Failure messages are stored in task results, not in the facts dictionary.
- An encrypted vault secret
  - Secrets are managed by Ansible Vault and are distinct from system facts.

**Hint:** Information gathered about the remote system.

### 7. Which module transfers files from the control node to the remote server?

- `move`
  - The "move" command is typically used for renaming or moving files already on the target.
- **`copy`** ✅
  - The "copy" module is designed to push local files from the control node to remote hosts.
- `push`
  - Ansible does not have a "push" module; file transfers are handled by the copy module.
- `fetch`
  - The "fetch" module pulls files from the remote host back to the local control node.

**Hint:** The name is very straightforward.

### 8. What does "Idempotency" mean in the context of automation?

- Increased execution speed
  - Execution speed is a performance metric, whereas idempotency refers to state consistency.
- **Consistent state results** ✅
  - An idempotent task ensures the system reaches the desired state without making redundant changes.
- Parallel task execution
  - Parallelism (forks) refers to running tasks simultaneously, not the consistency of the result.
- Secure data encryption
  - Data encryption is handled by Ansible Vault and is unrelated to idempotency.

**Hint:** Run it once, run it ten times, the result is the same.

### 9. Which keyword allows a task to run only if a specific condition is met?

- **`when`** ✅
  - The "when" keyword is the standard conditional used to control task execution logic.
- `only_if`
  - This is not a valid keyword; conditions in Ansible must be defined using the "when" statement.
- `check`
  - "check" refers to dry-run mode, which simulates changes without applying them.
- `match`
  - While used in regex, "match" is not a top-level keyword for task conditionals.

**Hint:** It works like an "if" statement.

### 10. Which tool is used to encrypt sensitive variables or files in Ansible?

- `ansible-crypt`
  - This is not a valid command; encryption is managed by the vault sub-command.
- **`ansible-vault`** ✅
  - Ansible Vault provides a mechanism to encrypt sensitive data like passwords or API keys.
- `ansible-secret`
  - While secrets are protected, the specific tool name is "ansible-vault".
- `ansible-secure`
  - This is not a valid CLI tool within the standard Ansible distribution.

**Hint:** Think of a secure room for valuables.

### 11. Which module is used to ensure a service is running and enabled on boot?

- `systemd`
  - While "systemd" is a module, the "service" module is the preferred cross-platform standard.
- **`service`** ✅
  - The "service" module manages service states and ensures they persist across system reboots.
- `daemon`
  - There is no "daemon" module; system services are managed via the service module.
- `process`
  - The "process" module is not used for high-level service state management.

**Hint:** The module name matches the Linux system manager.

### 12. What is the specific purpose of "Handlers" in an Ansible play?

- Handle execution errors
  - Errors are managed using "block" and "rescue" structures, not through handlers.
- **Run tasks upon notification** ✅
  - Handlers are special tasks triggered by "notify" when a change is detected in another task.
- Define global variables
  - Variables are defined in "vars" or "group_vars," not within the handlers section.
- Manage remote SSH keys
  - SSH keys are managed via the "authorized_key" module or connection configuration.

**Hint:** They only run if something has "changed".

### 13. Which file extension is standard for Ansible playbooks?

- `.json`
  - While Ansible uses JSON internally for results, playbooks are written in YAML.
- **`.yml`** ✅
  - Ansible playbooks are YAML documents, typically saved with the .yml or .yaml extension.
- `.ans`
  - There is no standard ".ans" extension; playbooks must use standard YAML extensions.
- `.cfg`
  - The ".cfg" extension is used for the Ansible configuration file, not for playbooks.

**Hint:** Yet Another Markup Language.

### 14. What does the "ansible_all_ipv4_addresses" variable represent?

- Control node IP list
  - Facts are gathered from the target host, not from the machine running Ansible.
- **Target host IP list** ✅
  - This is a gathered fact containing all IPv4 addresses assigned to the remote host.
- Cloud gateway IP list
  - Default facts focus on the local network interfaces of the target operating system.
- Subnet mask IP list
  - Subnet information is stored in different specific fact variables, not this broad list.

**Hint:** It is a type of "Fact".

### 15. Which flag validates playbook syntax without executing any tasks?

- `--check`
  - The "--check" flag is for dry-run mode, which simulates the execution rather than checking syntax.
- **`--syntax-check`** ✅
  - The "--syntax-check" flag validates the YAML and Ansible keywords without connecting to hosts.
- `--validate`
  - This is not a valid flag for the ansible-playbook command; use --syntax-check instead.
- `--dry-run`
  - Dry-run is achieved via "--check" and is different from a pure syntax validation.

**Hint:** You are "checking" the "syntax".

### 16. Which module is designed to modify a single specific line in a file?

- `file`
  - The "file" module manages file existence and permissions, not the internal text content.
- **`lineinfile`** ✅
  - The "lineinfile" module ensures a particular line is present or absent using regex matching.
- `replace`
  - The "replace" module is for changing all occurrences of a string, not managing a single line.
- `template`
  - The "template" module replaces the entire file content based on a source J2 template.

**Hint:** It uses a "regex" (regular expression).

### 17. Which keyword is used to iterate over a list of items in a task?

- `repeat`
  - This is not a valid Ansible keyword; iteration is handled by the loop keyword.
- `for_each`
  - While common in other languages and tools, "for_each" is not an Ansible keyword.
- **`loop`** ✅
  - The "loop" keyword is the modern, recommended way to iterate through lists in Ansible.
- `iterate`
  - This keyword does not exist in the Ansible DSL; loops must be explicitly defined.

**Hint:** It replaced the older "with_items".

### 18. What is an Ansible "Role" in a production environment?

- User access level
  - In Ansible, roles refer to architectural structure, not Identity and Access Management (IAM).
- **Reusable task structure** ✅
  - Roles provide a standardized directory structure to bundle and share tasks, variables, and files.
- Remote host type
  - Host types are defined in the inventory via groups, not through the roles mechanism.
- Privilege level flag
  - The privilege level is controlled by the "become" directive, not by roles.

**Hint:** A way to bundle playbooks and files into a reusable package.

### 19. Which module executes commands through the remote shell environment?

- `command`
  - The "command" module is safer but does not support shell variables, pipes, or redirects.
- **`shell`** ✅
  - The "shell" module runs commands through /bin/sh and supports shell-specific features like pipes.
- `raw`
  - The "raw" module bypasses Python entirely and is used for systems without Python installed.
- `script`
  - The "script" module runs a local script on the remote node after transferring it.

**Hint:** It is generally discouraged in favor of specific modules.

### 20. What is the default SSH port Ansible uses for Linux connections?

- 80
  - Port 80 is the default for unencrypted HTTP web traffic.
- 443
  - Port 443 is the standard for encrypted HTTPS web traffic.
- **22** ✅
  - Ansible uses the standard SSH port 22 for connecting to Linux and Unix-like servers.
- 5985
  - Port 5985 is the default for WinRM, which is used for Windows connections.

**Hint:** Standard SSH port.

### 21. Which file defines global settings like fork count and SSH timeouts?

- **`ansible.cfg`** ✅
  - The "ansible.cfg" file is the central configuration file that controls Ansible engine behavior.
- `settings.yml`
  - This is not a standard file name; Ansible settings are controlled via the .cfg file.
- `ansible.ini`
  - While the config file uses INI format, the required file name is ansible.cfg.
- `hosts.cfg`
  - This typically refers to an inventory file, not the core engine configuration.

**Hint:** Found in /etc/ansible/ or the current directory.

### 22. What does the "register" keyword do within a task?

- Adds a new host
  - Adding hosts is done via the inventory or the add_host module at runtime.
- **Saves task output** ✅
  - The "register" keyword captures the output of a task into a variable for use in later tasks.
- Defines a handler
  - Handlers are defined in their own section and triggered via the "notify" keyword.
- Encrypts a variable
  - Variable encryption is handled by Ansible Vault, not the register keyword.

**Hint:** Saves the output of a task for later use.

### 23. Which directive allows a playbook to continue if a task fails?

- **`ignore_errors: yes`** ✅
  - This directive prevents a specific task failure from stopping the rest of the play.
- `on_failure: skip`
  - This is not valid syntax; failures must be handled by ignore_errors or blocks.
- `force: yes`
  - The "force" parameter is usually a module-level argument to overwrite existing files.
- `continue: yes`
  - This is not a valid Ansible keyword; task flow is controlled by ignore_errors.

**Hint:** Use this for tasks that might fail but aren't critical.

### 24. Which module manages file properties like permissions and ownership?

- `directory`
  - "directory" is a state parameter used within the file module, not a module itself.
- **`file`** ✅
  - The "file" module is the primary tool for managing files, directories, and symlinks.
- `chown`
  - There is no "chown" module; ownership is managed through parameters in the file module.
- `attributes`
  - While it manages file attributes, the specific module name is "file".

**Hint:** A very common Linux command name.

### 25. What is "Ansible Galaxy"?

- Cloud hosting provider
  - Ansible is a management tool, not a hosting provider; it works across all clouds.
- **Content repository hub** ✅
  - Galaxy is a public platform for sharing and downloading community-built roles and collections.
- System monitoring tool
  - Monitoring is handled by tools like Prometheus or CloudWatch, not by Galaxy.
- Variable encryption tool
  - Encryption is the responsibility of Ansible Vault, not the Galaxy repository.

**Hint:** A hub for sharing Ansible content.

### 26. How is a host group defined in an INI-style inventory file?

- `<group_name>`
  - Angle brackets are not used in Ansible inventory files for group definitions.
- **`[group_name]`** ✅
  - In INI-style inventories, group names are enclosed in square brackets.
- `{group_name}`
  - Braces are used for variables and templates, not for defining inventory groups.
- `group: group_name`
  - This is the YAML-style inventory syntax, not the classic INI-style syntax.

**Hint:** Use square brackets.

### 27. What characterizes "Ad-hoc mode" in Ansible?

- Advanced debugging mode
  - Debugging is performed using the "debug" module or by increasing verbosity with -vvv.
- **Single task execution** ✅
  - Ad-hoc mode allows users to run single tasks directly from the CLI without a playbook.
- Parallel execution mode
  - Parallelism is a feature of both ad-hoc and playbook modes, not a separate mode itself.
- Windows-only access mode
  - Ad-hoc commands work across all supported operating systems, including Linux and Windows.

**Hint:** Running a single command without a playbook.

### 28. Which module is used to create files from Jinja2 templates?

- `jinja`
  - Jinja2 is the templating engine used by Ansible, but the module name is "template".
- **`template`** ✅
  - The "template" module renders Jinja2 templates into files on the remote target host.
- `render`
  - There is no "render" module; dynamic file creation is managed by the template module.
- `format`
  - The "format" module does not exist for file creation; use the template module instead.

**Hint:** The name is exactly what it does.

### 29. What is the primary function of the "debug" module?

- Stopping execution flow
  - Stopping a playbook is handled by the "fail" module, while "debug" allows it to continue.
- **Displaying variable values** ✅
  - The "debug" module is used to print messages or variable content to the console during execution.
- Fixing syntax errors
  - The "debug" module only displays information; it cannot automatically repair code errors.
- Logging into systems
  - System login is a core engine function and is not related to the debug module.

**Hint:** It prints information to the console.

### 30. What does the "Forks" setting control in Ansible?

- Ansible version count
  - The "forks" parameter relates to networking and concurrency, not software versions.
- **Parallel host connections** ✅
  - Forks determine the number of remote hosts Ansible communicates with simultaneously.
- CPU core requirements
  - While forks use system resources, they do not define a strict CPU core requirement.
- Playbook play count
  - The number of plays is defined by the playbook structure, not the forks configuration.

**Hint:** Number of parallel processes.
