An Ansible playbook fails intermittently when deploying web servers. The error message indicates that a required package is not available in the repository. Which approach would best ensure that the required packages are consistently available before the playbook runs?
Trap 1: Set 'ignore_errors: yes' on the package installation task and…
Ignoring errors can lead to an inconsistent system state.
Trap 2: Add retries and delay to the package installation task.
Retries only help with transient failures, not with permanently missing packages.
Trap 3: Use the 'get_url' module to download the package from an external…
While possible, it adds complexity and may not be a best practice.
- A
Set 'ignore_errors: yes' on the package installation task and handle the failure later.
Why it fails: Ignoring errors can lead to an inconsistent system state.
- B
Add retries and delay to the package installation task.
Why it fails: Retries only help with transient failures, not with permanently missing packages.
- C
Add a pre_task to run 'dnf update' or 'apt update' before the package installation.
A pre_task refreshing repository metadata with dnf update or apt update ensures package indexes are current before installation, addressing the intermittent 'package not available' failure caused by stale cache. This targets the actual constraint: repository metadata freshness, not package version pinning or mirror configuration.
- D
Use the 'get_url' module to download the package from an external source and install it manually.
Why it fails: While possible, it adds complexity and may not be a best practice.