Ansible Automation Quality Control & Assurance 2 — Questions and Answers
Question 1: Which Ansible module is used to verify that a service is running as part of a post-deployment quality check?
- service_facts (Correct answer)
- assert
- wait_for
- stat
Correct answer: service_facts
The `service_facts` module gathers service state information that can then be checked with `assert` to confirm a service is running.
Question 2: What does the `failed_when` directive do in an Ansible task?
- Retries a task until it succeeds
- Marks a task as failed based on a custom condition (Correct answer)
- Skips a task if it has previously failed
- Sends an alert when a task fails
Correct answer: Marks a task as failed based on a custom condition
`failed_when` overrides the default failure detection logic with a user-defined condition expression.
Question 3: In Ansible Molecule, what is the purpose of the `verify` phase?
- Installs the role under test
- Destroys the test infrastructure
- Runs assertions to confirm the role achieved its desired state (Correct answer)
- Lints the role's YAML syntax
Correct answer: Runs assertions to confirm the role achieved its desired state
The `verify` phase executes test assertions (via Testinfra, Goss, or Ansible tasks) to confirm the role produced the expected system state.
Question 4: Which command checks Ansible playbook syntax without executing it?
- ansible-playbook --dry-run
- ansible-playbook --check
- ansible-playbook --syntax-check (Correct answer)
- ansible-lint --parse-only
Correct answer: ansible-playbook --syntax-check
`ansible-playbook --syntax-check` parses the playbook and reports YAML and task syntax errors without running any tasks.
Question 5: What is the primary advantage of using `block` with `rescue` in quality-critical playbooks?
- It speeds up task execution by batching
- It lets you handle failures gracefully and run cleanup or alerting tasks (Correct answer)
- It automatically retries failed tasks
- It bypasses `become` privilege escalation
Correct answer: It lets you handle failures gracefully and run cleanup or alerting tasks
`rescue` runs when any task in the `block` fails, enabling structured error handling, rollback, or notification logic.
Question 6: Which tool integrates with Ansible to provide idempotency verification by running a role twice and checking for changes on the second run?
- ansible-lint
- Molecule idempotency test (Correct answer)
- Semaphore
- AWX job templates
Correct answer: Molecule idempotency test
Molecule's default test sequence includes an idempotency check that runs `converge` a second time and fails if any tasks report `changed`.
Question 7: What does `ansible-lint` rule `no-changed-when` enforce?
- Tasks using `shell` or `command` must define `changed_when` (Correct answer)
- Tasks must not use the `changed_when: false` shortcut
- The `when` condition must never be used with `changed_when`
- All tasks must report changes
Correct answer: Tasks using `shell` or `command` must define `changed_when`
The `no-changed-when` rule flags `command` and `shell` tasks that lack `changed_when`, since those modules always report `changed` by default without it.
Which Ansible module is used to verify that a service is running as part of a post-deployment quality check?