How do you keep a task from running when invoked with `--check`, because it only makes sense for real runs?
BeginnerScenarioPerformance, Testing and CI/CD
Answer
Situation read → Check-mode-aware logic.
What I'd do →
- ansible.builtin.command: /opt/app/send-metrics
when: not ansible_check_mode
Why → ansible_check_mode is a special variable that is true during --check.
Interview tip → ansible_diff_mode is the equivalent for --diff.
More on Performance, Testing and CI/CD
A playbook that touches 200 hosts takes 40 minutes. Where do you start tuning?IntermediateYou install 15 packages with a loop and it is slow.BeginnerHow would you test a role in CI before it reaches production?IntermediateWhat would a Molecule `verify.yml` check for an Nginx role?IntermediateMolecule's idempotence step fails. How do you find the offending task?IntermediateDesign a CI pipeline for an Ansible repo.Advanced