`Unable to start service myapp: Job for myapp.service failed because the control process exited with error code.`
BeginnerTroubleshootingModules, Idempotency and Handlers
Answer
Likely causes → The application itself fails to start (bad config, port in use, missing environment), or the unit file was changed but systemd was never reloaded, so it still runs the old definition.
Diagnose →
ansible web01 -b -m command -a 'systemctl status myapp --no-pager'
ansible web01 -b -m command -a 'journalctl -u myapp -n 50 --no-pager'
Fix → Fix the application error shown in the journal. After changing a unit file, reload systemd:
- ansible.builtin.systemd:
name: myapp
state: started
enabled: true
daemon_reload: true
Prevent → Notify a handler with daemon_reload: true whenever a unit file changes, and add a health check (uri or wait_for) after starting.
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