Ansible Automation Quality Control & Assurance 3 — Questions and Answers
Question 1: Which Ansible feature allows you to test variable values before a play runs, preventing misconfigured deployments?
- pre_tasks with assert (Correct answer)
- handlers
- vars_prompt
- include_vars
Correct answer: pre_tasks with assert
Using `assert` inside `pre_tasks` lets you validate required variables and their values before any deployment tasks execute.
Question 2: What is the role of `uri` module in post-deployment quality assurance?
- Generates SSL certificates for web services
- Sends HTTP requests to verify endpoints are reachable and returning expected responses (Correct answer)
- Downloads files from remote URLs
- Parses JSON API responses into Ansible variables
Correct answer: Sends HTTP requests to verify endpoints are reachable and returning expected responses
The `uri` module can make HTTP/HTTPS requests and assert on status codes, response bodies, or headers to confirm a web service is healthy.
Question 3: In a CI/CD pipeline, at which stage should `ansible-lint` typically run?
- After production deployment
- Before the playbook is executed, in the static analysis stage (Correct answer)
- Only when a deployment fails
- During the Molecule converge phase
Correct answer: Before the playbook is executed, in the static analysis stage
Running `ansible-lint` in the static analysis (pre-execution) stage catches code quality issues before any infrastructure is touched.
Question 4: Which Molecule driver is most commonly used for local role testing without cloud costs?
- EC2
- Docker (Correct answer)
- Azure
- Vagrant
Correct answer: Docker
The Docker driver spins up containers locally, making it the most accessible and cost-free option for Molecule role testing.
Question 5: What does the `validate` parameter on modules like `template` or `copy` do?
- Checks Jinja2 syntax before rendering
- Runs a specified command to validate the file before placing it in its final destination (Correct answer)
- Verifies file ownership and permissions
- Confirms the destination directory exists
Correct answer: Runs a specified command to validate the file before placing it in its final destination
The `validate` parameter runs a command (e.g., `nginx -t %s`) on a temp copy of the file, only finalizing the copy if the command succeeds.
Question 6: Which Ansible built-in callback plugin helps quality assurance by showing a task-level summary of changed, failed, and skipped counts?
- json
- profile_tasks
- default (Correct answer)
- timer
Correct answer: default
The `default` callback plugin produces the standard play recap at the end of every run, summarizing ok, changed, unreachable, failed, and skipped counts.
Question 7: What is the purpose of `molecule test` compared to `molecule converge`?
- `molecule test` only checks syntax; `molecule converge` deploys
- `molecule test` runs the full lifecycle including create, converge, verify, and destroy; `molecule converge` only applies the role (Correct answer)
- `molecule test` tests one scenario; `molecule converge` tests all scenarios
- `molecule test` is faster because it skips the verify phase
Correct answer: `molecule test` runs the full lifecycle including create, converge, verify, and destroy; `molecule converge` only applies the role
`molecule test` executes the complete test sequence (create → converge → idempotency → verify → destroy), while `molecule converge` only runs the role application step.
Which Ansible feature allows you to test variable values before a play runs, preventing misconfigured deployments?