`--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.
More on Modules, Idempotency and Handlers
`ERROR! The requested handler 'Restart nginx' was not found in either the main handlers list nor in the listening handlers list`BeginnerA handler named `restart {{ app_service }}` is never found when notified as `restart myapp`AdvancedA `command` task reports `changed` on every run, and the Molecule idempotence check failsBeginner`curl ... | tar xz` fails on the host but the `shell` task reports successIntermediate`lineinfile` appends the same line again on every runIntermediate`lineinfile` with `backrefs: true` reports `ok` but the line was never addedIntermediate