Ansible Automation Research & Evidence-Based Practice 2 — Questions and Answers
Question 1: Which Ansible module is the recommended evidence-based approach for managing packages across multiple Linux distributions in a single playbook?
- yum
- apt
- package (Correct answer)
- dnf
Correct answer: package
The `package` module is distribution-agnostic and lets a single task manage packages on any supported OS without conditional logic.
Question 2: What does the Ansible documentation recommend as the primary method to test a playbook's changes without applying them?
- ansible-lint
- ansible-playbook --check (Correct answer)
- ansible-test sanity
- ansible-review
Correct answer: ansible-playbook --check
`ansible-playbook --check` runs a dry-run that predicts changes without modifying the target hosts.
Question 3: According to Ansible best practices, where should group-specific variables be stored to keep inventory readable?
- In the inventory file inline
- In host_vars/ directories
- In group_vars/ directories (Correct answer)
- In the playbook vars block
Correct answer: In group_vars/ directories
The `group_vars/` directory is the recommended location for variables scoped to an inventory group.
Question 4: Which evidence-based practice does Ansible Galaxy promote for sharing reusable automation content?
- Copying playbooks into every project
- Using roles and collections (Correct answer)
- Embedding all tasks in a single file
- Storing playbooks in a shared NFS mount
Correct answer: Using roles and collections
Ansible Galaxy promotes roles and collections as the standard, shareable units of reusable automation.
Question 5: What is the best-practice reason for using `become: yes` at the task level rather than the play level?
- It improves playbook speed
- It limits privilege escalation to only tasks that require it (Correct answer)
- It avoids password prompts entirely
- It is required for Windows hosts
Correct answer: It limits privilege escalation to only tasks that require it
Applying `become` at the task level follows the principle of least privilege by escalating only where necessary.
Question 6: According to Ansible's official style guide, what is the recommended YAML syntax for boolean values in playbooks?
- yes/no (lowercase)
- true/false (lowercase) (Correct answer)
- True/False (capitalized)
- 1/0 (integers)
Correct answer: true/false (lowercase)
Ansible's style guide recommends `true`/`false` in lowercase to align with standard YAML 1.2 boolean representation.
Question 7: What research-backed practice does using `ansible-lint` support in an Ansible project?
- Syntax highlighting in editors
- Enforcing coding standards and catching common errors early (Correct answer)
- Encrypting vault files automatically
- Generating HTML documentation from playbooks
Correct answer: Enforcing coding standards and catching common errors early
`ansible-lint` statically analyzes playbooks to enforce best practices and catch errors before execution.
Which Ansible module is the recommended evidence-based approach for managing packages across multiple Linux distributions in a single playbook?