60 Practice Questions & Answers
Which Ansible module is used to manage systemd services and their enabled/disabled states on target systems?
-
A
daemon
-
B
service
-
C
init
-
D
systemd
✓ Correct
Explanation
The systemd module is the modern Ansible module for managing systemd services, enabling/disabling them, and controlling their state. The service module is legacy and less preferred for newer systems.
In Ansible, what is the primary purpose of using the `block` keyword in a playbook?
-
A
To create loop iterations across multiple hosts
-
B
To group tasks logically and apply common attributes like error handlers and conditions
✓ Correct
-
C
To prevent concurrent task execution
-
D
To encrypt sensitive data within the playbook
Explanation
The block keyword allows grouping of tasks to apply rescue/always blocks, common variables, and conditions to all contained tasks, providing better error handling and organization.
When using Ansible's `become` privilege escalation, which configuration parameter specifies the method to use for privilege escalation?
-
A
escalation_type
-
B
become_user
-
C
privilege_mode
-
D
become_method
✓ Correct
Explanation
The become_method parameter determines the escalation method (sudo, su, pbrun, etc.), while become_user specifies which user to escalate to.
Which of the following best describes the role of `ansible-navigator` in modern Ansible automation?
-
A
It automatically generates playbooks from system specifications
-
B
It removes the need for inventory files entirely
-
C
It replaces ansible-playbook and provides execution environment support with better UI
✓ Correct
-
D
It is exclusively used for cloud deployments
Explanation
ansible-navigator is the next-generation tool that replaces ansible-playbook, provides execution environment support, improved logging, and a better user interface for running playbooks.
What is the correct syntax to register a variable from a task's output in Ansible?
-
A
variable: output_var
-
B
store: output_var
-
C
register: output_var
✓ Correct
-
D
capture: output_var
Explanation
The register keyword is used to capture task output into a variable for later use in subsequent tasks or conditionals.
In Ansible, which filter would you use to convert a string to uppercase?
-
A
uppercase
-
B
capitalize
-
C
upper
✓ Correct
-
D
to_upper
Explanation
The upper filter converts a string to uppercase in Jinja2 templates used by Ansible. The capitalize filter only capitalizes the first letter.
What is the primary function of the `handlers` section in an Ansible playbook?
-
A
To define error recovery procedures
-
B
To handle SSH connection failures
-
C
To manage user authentication and authorization
-
D
To execute tasks only when notified by other tasks, typically used for service restarts
✓ Correct
Explanation
Handlers are special tasks that execute only when notified by other tasks through the notify keyword, commonly used to restart services when configuration changes.
Which Ansible module is most appropriate for executing arbitrary commands on remote hosts without using shell interpretation?
-
A
script
-
B
shell
-
C
command
✓ Correct
-
D
raw
Explanation
The command module executes commands directly without shell interpretation, making it safer and more predictable. The shell module invokes /bin/sh for processing.
What does the `ansible-inventory` command primarily allow you to do?
-
A
Automatically scan your network for new hosts
-
B
List and display inventory information in various formats including host variables and group membership
✓ Correct
-
C
Create new hosts in your inventory
-
D
Encrypt inventory files
Explanation
ansible-inventory displays inventory information, shows host/group variables, can output in JSON or YAML format, and helps debug inventory issues.
In Ansible Galaxy, what is a 'collection'?
-
A
A packaged unit containing playbooks, roles, modules, plugins, and documentation that can be shared and reused
✓ Correct
-
B
A method of encrypting sensitive variables
-
C
A temporary storage location for generated playbooks
-
D
A backup mechanism for protecting playbook history
Explanation
Collections are distributable packages containing roles, modules, plugins, and documentation that extend Ansible functionality and can be installed from Ansible Galaxy.
Which of the following statements about Ansible idempotency is correct?
-
A
Idempotency requires manual verification after each playbook run
-
B
Idempotent tasks produce the same result regardless of how many times they are executed, changing nothing if the desired state is already met
✓ Correct
-
C
Only shell tasks can be idempotent in Ansible
-
D
Idempotent tasks can only be run once per system
Explanation
Idempotency is a core Ansible principle where running a playbook multiple times produces the same result without making unnecessary changes if the desired state is already achieved.
What is the purpose of the `meta` module in Ansible?
-
A
To tag tasks with metadata for filtering
-
B
To perform Ansible-level operations like clearing cache, refreshing inventory, and flushing handlers
✓ Correct
-
C
To define metadata about the playbook in comments
-
D
To gather facts about remote systems
Explanation
The meta module executes Ansible-specific operations such as 'flush_handlers', 'clear_facts', and 'refresh_inventory' without connecting to target hosts.
Which Jinja2 conditional statement is used in Ansible templates to test if a variable is defined?
-
A
{% if var is defined %}
✓ Correct
-
B
{% if var != None %}
-
C
{% if exists(var) %}
-
D
{% if var %}
Explanation
The 'is defined' test checks whether a variable has been defined in Ansible's context, which is more reliable than checking for truthiness or None values.
In an Ansible role, what is the standard purpose of the `defaults` directory?
-
A
To provide default variables with low precedence that can be easily overridden
✓ Correct
-
B
To store default SSH configurations
-
C
To cache downloaded files
-
D
To define role dependencies and metadata
Explanation
The defaults directory contains main.yml with role variables that have the lowest precedence in Ansible's variable hierarchy, allowing easy customization.
What is the correct way to conditionally execute a task in Ansible using host facts?
-
A
Create separate playbooks for each condition
-
B
Use the `if_fact` keyword in the module parameters
-
C
Use the `when` keyword with a conditional expression referencing ansible_facts
✓ Correct
-
D
Use the `fact_condition` keyword at the play level
Explanation
The `when` keyword allows conditional execution based on variables, facts, and expressions, such as: when: ansible_facts['os_family'] == 'RedHat'
Which Ansible module would you use to check if a file exists on a remote system and gather information about it?
-
A
find
-
B
file
-
C
copy
-
D
stat
✓ Correct
Explanation
The stat module retrieves file status and metadata information similar to the Linux stat command, without modifying the file.
In Ansible tower/AWX, what is a 'credential'?
-
A
A playbook parameter that stores sensitive data
-
B
A role-based access control mechanism
-
C
A backup encryption key for playbooks
-
D
A secured storage object containing credentials for SSH, database, cloud, or other authentication requirements
✓ Correct
Explanation
Credentials in AWX/Tower are secure, encrypted storage objects for various authentication methods used by projects, inventory sources, and job templates.
What does the `async` keyword do when used in an Ansible task?
-
A
Runs the task on multiple hosts in parallel
-
B
Makes the playbook run in the background
-
C
Specifies the maximum time in seconds for the task to complete before timing out and allows the playbook to continue
✓ Correct
-
D
Enables encryption for the task
Explanation
The async keyword specifies a timeout period and allows Ansible to continue without waiting for task completion, useful for long-running tasks.
Which Ansible best practice involves using `ansible-vault` to protect sensitive data?
-
A
Replacing all variables with hardcoded values
-
B
Encrypting specific variables or files containing passwords and API keys with a vault password
✓ Correct
-
C
Encrypting entire playbooks to prevent modification
-
D
Using SSH keys instead of passwords in inventory
Explanation
ansible-vault encrypts specific sensitive files and variables at rest, which can be decrypted at runtime with a password or key file.
In Ansible, what is the purpose of the `loop` keyword compared to the legacy `with_*` constructs?
-
A
loop is the modern standard for iteration and provides consistent behavior across all item types
✓ Correct
-
B
loop only works with lists while with_* works with all data types
-
C
loop is only for use in roles while with_* is for playbooks
-
D
loop is slower but more flexible
Explanation
The loop keyword is the recommended modern approach for iteration in Ansible, providing consistent and predictable behavior, replacing the older with_items, with_dict, etc.
What is the correct syntax to use an Ansible filter to extract the first element from a list?
-
A
{{ mylist[0] }}
-
B
{{ mylist | index(0) }}
-
C
{{ first(mylist) }}
-
D
{{ mylist | first }}
✓ Correct
Explanation
The first filter in Jinja2 templates returns the first element of a list, using the pipe syntax for Ansible filters.
Which strategy in Ansible determines how tasks are distributed and executed across multiple hosts?
-
A
free strategy allows each host to run tasks as quickly as possible without waiting for others
-
B
linear strategy executes tasks sequentially on each host
-
C
only linear strategy is available in current versions
-
D
Both 'linear' and 'free' are valid strategies with different behaviors
✓ Correct
Explanation
Linear strategy is the default and executes tasks sequentially across all hosts before moving to the next task. Free strategy lets each host progress independently.
In an Ansible playbook, what is the difference between `vars` and `vars_files`?
-
A
vars defines variables inline in the playbook while vars_files loads variables from external YAML files
✓ Correct
-
B
They are identical and can be used interchangeably
-
C
vars_files requires ansible-vault while vars does not
-
D
vars is for host-level variables and vars_files is for play-level variables
Explanation
vars allows inline variable definition within the playbook, while vars_files loads variables from external files, promoting better organization and reusability.
What does the `check` mode in Ansible do?
-
A
It performs a dry-run, showing what changes would be made without actually making them on remote systems
✓ Correct
-
B
It checks if all required modules are installed
-
C
It verifies the inventory file for errors
-
D
It validates the syntax of the playbook without executing it
Explanation
Check mode (--check flag) performs a dry-run simulation showing what changes would occur, without actually modifying target systems, useful for validation before execution.
Which Ansible plugin type is responsible for processing task return values and determining task status?
-
A
callback
✓ Correct
-
B
connection
-
C
filter
-
D
lookup
Explanation
Callback plugins process task results and return values, controlling output formatting and status reporting. Other plugin types handle different aspects like variable lookups or connections.
You are designing a playbook that needs to handle multiple inventory sources dynamically. Which inventory plugin would you use to merge inventory from both static files and cloud providers in a single play?
-
A
The merge inventory plugin combined with host_list
-
B
The constructed inventory plugin
-
C
Multiple inventory sources cannot be merged; separate plays are required
-
D
The composite inventory plugin with proper ordering in ansible.cfg
✓ Correct
Explanation
The composite inventory plugin allows multiple inventory sources to be merged and prioritized using the enable_plugins directive in ansible.cfg, enabling dynamic inventory composition from multiple backends.
What is the purpose of using ansible-inventory command with the --graph option?
-
A
To show network connectivity between managed hosts
-
B
To generate a graphical visualization file in PNG format
-
C
To create a directed acyclic graph for task dependencies
-
D
To display inventory in a hierarchical tree format showing host-group relationships
✓ Correct
Explanation
The --graph option displays the inventory as a hierarchical tree, showing which hosts belong to which groups and group relationships, useful for understanding inventory structure.
You need to create a custom Jinja2 filter that processes host variables. Where should this filter be placed to ensure it loads automatically with your playbooks?
-
A
In the ~/.ansible/plugins/filters/ directory only
-
B
In the roles/common/library directory
-
C
In /usr/lib/python3.9/site-packages/ansible/plugins/filter/
-
D
In a filter_plugins directory at the same level as the playbook
✓ Correct
Explanation
Ansible automatically loads custom filter plugins from a filter_plugins directory relative to the playbook location, making it the standard practice for local custom filters.
What is the correct syntax to register a variable and then use a failed_when condition to determine if a task has failed based on that variable's content?
-
A
register: result followed by failed_when: 'result.rc != 0' in a subsequent task
-
B
Use register: result and set failed_when: result.rc != 0 within the same task
✓ Correct
-
C
register: result | failed_when: result.rc != 0
-
D
Variables registered cannot be checked with failed_when in the same playbook
Explanation
The failed_when directive is set within the same task block as the register directive, allowing you to define custom failure conditions based on task output immediately.
You are using Ansible to manage both Linux and Windows hosts. Which callback plugin would you enable to get detailed, color-coded output showing task status changes across both platforms?
-
A
The default callback plugin with force_color=True
✓ Correct
-
B
The unixy callback plugin
-
C
The debug callback plugin
-
D
The profile_tasks callback plugin
Explanation
The default callback plugin with force_color=True option in ansible.cfg provides cross-platform colored output showing task status, and works consistently on both Linux and Windows.
When using the block directive, what is the scope of variables registered within a block when an error occurs and the rescue section executes?
-
A
Only explicitly passed variables via set_fact are available in rescue
-
B
Registered variables from the block are accessible throughout the rescue section and subsequent tasks
✓ Correct
-
C
Variables must be re-registered in the rescue section to be used
-
D
Variables are not accessible in the rescue section
Explanation
Variables registered in the block section remain accessible in the rescue and always sections, allowing error handling logic to reference data from failed tasks.
You need to dynamically include tasks based on the OS family of the target host. What is the difference between using include_tasks and import_tasks for this scenario?
-
A
There is no functional difference between them for conditional inclusion
-
B
include_tasks processes conditionals at runtime; import_tasks processes them at parse time
✓ Correct
-
C
include_tasks cannot use conditionals with OS family variables
-
D
import_tasks is always faster regardless of conditions
Explanation
include_tasks evaluates conditionals dynamically at execution time, allowing OS family conditionals to work properly, while import_tasks resolves everything at parse time.
What Ansible feature allows you to define a set of variables that should be encrypted and automatically decrypted during playbook execution?
-
A
Ansible Vault with a vault-encrypted file
✓ Correct
-
B
The encrypt_string option in ansible.cfg
-
C
Variable encryption is not a native Ansible feature
-
D
Using the cryptography module in a custom filter
Explanation
Ansible Vault encrypts files containing sensitive variables and automatically decrypts them when the vault password is provided during playbook execution.
You are troubleshooting a playbook that uses the loop keyword with a large list of items. Which strategy would best reduce the amount of output while still showing which specific items failed?
-
A
Use the quiet module parameter in the task
-
B
Split the loop into smaller loops with fewer items
-
C
Reduce the verbosity to -v instead of -vv
-
D
Set loop_control with label to show only key identifying information
✓ Correct
Explanation
The loop_control label option allows you to specify which item attribute to display, significantly reducing output clutter while maintaining item-level visibility in failures.
When using the vars_prompt feature, how can you mark a variable as sensitive so its value is not echoed to the terminal during input?
-
A
Add the variable to no_log: true at the play level
-
B
Set private: true in the variable definition
-
C
The private keyword combined with no_echo directive in vars_prompt
✓ Correct
-
D
Use prompt_sensitive: true parameter
Explanation
The no_echo option in the vars_prompt variable definition prevents displaying the input value, similar to password prompts, protecting sensitive information during interactive playbook execution.
You need to run a task only on hosts where a specific package is already installed. Which conditional should you use to check installed packages?
-
A
when: ansible_packages | select('match', 'packagename')
-
B
when: 'packagename' in ansible_packages.keys()
-
C
Use the package_facts module with register and check the result
✓ Correct
-
D
when: ansible_facts.packages.packagename is defined
Explanation
The package_facts module gathers information about installed packages and stores it in ansible_facts.packages, allowing you to reliably check package installation status in conditionals.
What is the purpose of the meta: clear_host_errors task in a playbook?
-
A
To reset the failed status of hosts so they can continue in subsequent plays
✓ Correct
-
B
To remove all gathered facts from the host
-
C
To clear networking errors and reconnect to unreachable hosts
-
D
To clear Ansible internal cache on the control node
Explanation
meta: clear_host_errors resets the failed flag for hosts that have failed tasks, allowing them to participate in subsequent plays without being skipped due to previous failures.
You are creating a role that should apply different configurations based on the host's memory size. How would you best structure this using role variables?
-
A
Use vars/main.yml exclusively for all memory-based variables
-
B
Create multiple roles for each memory configuration level
-
C
Use defaults/main.yml with base values and define memory-specific vars in separate files included with conditionals
✓ Correct
-
D
Only use group_vars to avoid cluttering roles/main.yml
Explanation
Storing defaults in defaults/main.yml allows overrides while using conditional includes of memory-specific variable files provides clean, maintainable configuration management within a role.
When using the ansible.builtin.wait_for module, what is the default port checked if you specify a host without explicitly setting the port parameter?
-
A
No default port; the port parameter is mandatory
-
B
Port 22 for SSH
✓ Correct
-
C
Port 443 for HTTPS
-
D
Port 80 for HTTP
Explanation
The wait_for module defaults to checking port 22 (SSH) when only a host is specified, making it useful for waiting for SSH availability after server startup.
You need to validate that a playbook will execute correctly against your infrastructure without making any changes. What command-line option should you use?
-
A
--validate to test connectivity without execution
-
B
--syntax-check to verify YAML syntax only
-
C
--dry-run to simulate the entire playbook execution
-
D
--check combined with --diff to preview all changes
✓ Correct
Explanation
The --check option runs the playbook in check mode (no changes applied) and --diff shows what would change, allowing you to validate the playbook without affecting the infrastructure.
What does the serial keyword do in a play, and what is its impact on task execution order?
-
A
It limits concurrent host execution to a specified number, executing tasks sequentially on smaller batches
✓ Correct
-
B
It serializes variable values to prevent race conditions
-
C
It forces all tasks to run in serial order regardless of parallelism settings
-
D
It requires all playbook execution to use a single-threaded connection
Explanation
The serial keyword limits the number of hosts processing tasks simultaneously, allowing controlled batch deployments where later batches depend on earlier ones completing successfully.
You have a role that should not be applied to a specific subset of hosts based on inventory group membership. Which approach best achieves this?
-
A
Define hosts as 'all:!excluded_group' in the play hosts directive
✓ Correct
-
B
Use pre_tasks with a meta: end_host task when group conditions are met
-
C
Remove the hosts from the inventory before running the playbook
-
D
Use a conditional with ansible_groups in the role's tasks
Explanation
The hosts directive supports negation syntax using '!' to exclude specific groups, providing the cleanest way to prevent role application to certain host subsets at the play level.
What is the correct way to pass extra variables to an ansible-playbook command that contains special characters and spaces?
-
A
Both options A and B are valid depending on the use case
✓ Correct
-
B
ansible-playbook site.yml --extra-vars @vars.yml for file-based variables
-
C
ansible-playbook site.yml -e "var1='value with spaces'"
-
D
Use environment variables instead with ANSIBLE_VAR prefix
Explanation
Both methods are valid: inline variables with -e and proper quoting, or file-based variables with @filename. The choice depends on complexity and whether values are reusable.
When implementing role-based access control, which directory structure should you use to organize roles by function or environment?
-
A
Create separate playbooks for each environment, referencing the same roles directory
-
B
Store all roles in a single flat roles/ directory and use conditionals within tasks
-
C
Create multiple roles/ directories in ansible.cfg using the roles_path directive
✓ Correct
-
D
Use roles/ directory with subdirectories for environment-specific role variants
Explanation
The roles_path in ansible.cfg can specify multiple colon-separated paths, allowing you to organize roles by environment or function while maintaining clear separation of concerns.
You need to ensure a task only executes if the preceding task's result changed the target system. Which conditional expression is correct?
-
A
when: result is changed
✓ Correct
-
B
when: previous_task | changed
-
C
when: ansible_task_changed == true
-
D
when: task_name.changed
Explanation
The is changed test is the correct Jinja2 test to check if a registered variable indicates a system change occurred during task execution.
What is the advantage of using the include_role vs. import_role directives when you have conditional logic that determines which roles should be applied?
-
A
include_role evaluates conditionals at runtime, allowing dynamic role application based on gathered facts
✓ Correct
-
B
import_role can handle conditionals; include_role cannot
-
C
They are functionally identical for conditional role inclusion
-
D
include_role must be used in handlers; import_role in tasks
Explanation
include_role processes conditionals at execution time using gathered facts, enabling dynamic role selection, while import_role resolves everything at parse time making it less flexible.
You are designing a playbook that manages configuration across both RHEL and Debian-based systems. How should you structure variable overrides to ensure OS-specific values are applied correctly?
-
A
Use vars/main.yml in roles with explicit OS checks in every task
-
B
Create group_vars directories matching distribution group names and set distribution variables
✓ Correct
-
C
Use ansible_os_family in conditionals throughout the playbook instead of separate variables
-
D
Maintain a single defaults/main.yml and override it entirely per system
Explanation
Creating group_vars with directory names matching distribution groups (e.g., group_vars/redhat/, group_vars/debian/) allows variables to be applied based on group membership, cleanly separating OS-specific configurations.
When using the assert module, what is the correct syntax to provide a custom failure message?
-
A
assert module does not support custom messages
-
B
assert: { that: condition, fail_msg: 'Custom message' }
✓ Correct
-
C
assert: condition with error_message: 'Custom message'
-
D
Use assert with that and message parameters in key-value format
Explanation
The assert module uses the fail_msg parameter to provide custom error messages when assertions fail, allowing descriptive debugging information.
What is the purpose of the ansible.builtin.copy module's backup parameter, and when should it be used?
-
A
It creates backups only on the first run of the playbook
-
B
It creates a timestamped backup of the original file before replacing it
✓ Correct
-
C
It requires remote backup storage to be configured before copying
-
D
It enables checksum verification during the copy operation
Explanation
Setting backup: yes creates a timestamped backup file of the original before overwriting, useful for configuration management when rollback capability is needed.
You need to create a playbook that runs tasks at specific times using cron scheduling. Which Ansible module should you use, and what is the configuration best practice?
-
A
Use systemd timer units via the service module instead of cron
-
B
Ansible cannot manage scheduled tasks; use external tools like Foreman
-
C
Use ansible.builtin.shell with crontab commands directly
-
D
Use the cron module to define scheduled tasks, with service: cron in a handler to reload cron
✓ Correct
Explanation
The cron module manages cron jobs idempotently and is the recommended approach for Ansible-based cron scheduling, though systemd timers are also viable on modern systems.
When using Ansible Tower/AWX, which credential type is used to authenticate to a remote Ansible host via SSH?
-
A
Machine credential
✓ Correct
-
B
Network credential
-
C
Container credential
-
D
Cloud credential
Explanation
Machine credentials in Ansible Tower/AWX are used for SSH authentication to managed hosts. They contain username, password, or SSH key information needed for host connectivity.
You need to implement role-based access control (RBAC) in Ansible Tower to restrict a team's ability to execute only specific job templates. Which Tower feature should you configure?
-
A
Inventory access lists
-
B
User SSH key restrictions
-
C
Team permissions and role assignments
✓ Correct
-
D
Organization permissions
Explanation
Ansible Tower's RBAC system uses team permissions and role assignments to control which users and teams can execute, modify, or view specific job templates and resources.
When writing a custom Ansible module in Python, which class must your module inherit from to ensure proper integration with Ansible's module framework?
-
A
AnsibleModule
✓ Correct
-
B
ModuleHelper
-
C
BaseAnsibleClass
-
D
AnsibleBase
Explanation
Custom Ansible modules in Python must instantiate or work with the AnsibleModule class, which provides the interface for argument parsing, file operations, and result handling required by Ansible's execution framework.
You are debugging an Ansible playbook that uses handlers. The handler is defined but never executes even though a task with 'notify' is changed. What is the most likely cause?
-
A
The task did not report a changed status because it used check mode
-
B
Handlers cannot be used in the same play as roles that have their own handlers
-
C
The handler name does not exactly match the notify statement, including case sensitivity and whitespace
✓ Correct
-
D
Handlers must be defined before tasks in the playbook
Explanation
Handler names must match the notify statement exactly, including case and whitespace. Even minor differences in spelling or formatting will prevent handler execution despite task changes.
In an Ansible playbook, you need to conditionally include an entire task file based on the value of a variable. Which approach is most appropriate?
-
A
Use 'set_fact' to validate the variable before running any tasks
-
B
Use 'include_tasks' with a 'when' clause at the include statement level
✓ Correct
-
C
Use 'block' with multiple 'when' conditions for each task individually
-
D
Use 'import_tasks' with conditional logic inside the included file only
Explanation
The 'include_tasks' module supports 'when' conditions at the include level, allowing an entire task file to be conditionally included based on variable values. This is more efficient than checking conditions on individual tasks.
You are using Ansible Vault to encrypt sensitive data. After encrypting a file with vault, how should you provide the vault password when running a playbook that uses this encrypted file?
-
A
Use the '--vault-password-file' or '--ask-vault-password' option with ansible-playbook command
✓ Correct
-
B
Store the password in the inventory file and reference it via a variable
-
C
Add the vault password directly to the encrypted file header
-
D
Set the ANSIBLE_VAULT_PASSWORD environment variable before execution
Explanation
Ansible provides the '--vault-password-file' option to read a password from a file or '--ask-vault-password' to prompt the user. These are the standard, secure methods for providing vault passwords at runtime.
When developing a complex playbook with multiple roles, you notice that variable precedence is causing unexpected behavior. Which of the following represents the CORRECT variable precedence order from lowest to highest in Ansible?
-
A
Role defaults, role vars, inventory variables, playbook vars, extra vars
✓ Correct
-
B
Extra vars, playbook vars, inventory variables, role vars, role defaults
-
C
Role defaults, inventory variables, role vars, playbook vars, extra vars
-
D
Inventory variables, role defaults, role vars, playbook vars, extra vars
Explanation
Ansible's variable precedence from lowest to highest is: role defaults, role vars, inventory variables, playbook vars, and extra vars (passed via -e flag). This allows maximum flexibility in variable overrides.
You need to create an Ansible role that can work across multiple operating system families with different package managers and configuration file locations. What is the best practice approach?
-
A
Create a single role that includes all configurations and relies on users to edit the role files for their OS
-
B
Use 'include_vars' with OS-specific variable files and conditional tasks based on 'ansible_os_family'
✓ Correct
-
C
Create separate roles for each OS family and call them conditionally in your playbook
-
D
Store all OS-specific logic in the playbook using complex 'when' statements and 'set_fact' tasks
Explanation
Using 'include_vars' with variable files organized by OS family and conditional tasks based on 'ansible_os_family' is the recommended approach for multi-OS roles, keeping the role reusable and maintainable.
In Ansible Tower, you configure a job template to use a credential store integration with HashiCorp Vault. What must be set up first to enable this functionality?
-
A
A custom webhook that triggers Vault to generate temporary credentials for the job duration
-
B
An external inventory script that queries Vault for all required credentials before job execution
-
C
A Vault credential in Tower that contains the Vault server URL and authentication method, plus a credential type that references Vault templates
✓ Correct
-
D
An SSH key installed on the Vault server with write permissions for Tower's service account
Explanation
Ansible Tower's credential store integration with HashiCorp Vault requires creating a Vault credential type that specifies the Vault server URL and authentication method (e.g., AppRole, token), which is then referenced in job templates to retrieve secrets dynamically.
You are writing an Ansible playbook that must collect system facts from a newly provisioned server that may take several minutes to become fully responsive. What approach best handles potential timing issues?
-
A
Use 'async' and 'poll' to run 'setup' asynchronously with a timeout parameter set to maximum integer value
-
B
Use a 'wait_for' task to verify SSH connectivity before running 'setup', potentially with retries
✓ Correct
-
C
Use 'gather_facts: no' and manually collect facts with a 'setup' task that has no timeout
-
D
Use 'setup' module directly without any special handling
Explanation
The best practice is to use 'wait_for' to ensure SSH connectivity and the system is ready before attempting to gather facts, allowing for retries and reasonable timeouts rather than leaving tasks unhandled or with infinite waits.