Interview Prep/Ansible/Modules, Idempotency and Handlers

`--check` fails with `Could not find the requested service nginx` on a fresh host

IntermediateTroubleshootingModules, Idempotency and Handlers
Answer

Likely causes → In check mode, the package install is only simulated. The next task tries to manage a service whose unit file does not exist yet, so it fails.

Fix → Let dependent tasks tolerate check mode:

- ansible.builtin.service:
    name: nginx
    state: started
  ignore_errors: "{{ ansible_check_mode }}"

Or skip them with when: not ansible_check_mode.

Prevent → Check mode is most useful against hosts that are already configured, for drift detection. Do not expect a clean dry run on a fresh host.

All Ansible questions Roadmap: Ansible

More on Modules, Idempotency and Handlers