Interview Prep/Ansible/Playbook Design, Handlers and Idempotency

Your teammate used `command: systemctl restart app` in tasks. What do you say in review?

BeginnerScenarioPlaybook Design, Handlers and Idempotency
Answer

Situation read → Non-idempotent and reports changed every run.

What I'd do → Replace with a module and a handler.

handlers:
  - name: Restart app
    ansible.builtin.systemd:
      name: app
      state: restarted
      daemon_reload: true

Why → Modules report real state; handlers restart only when something changed.

Interview tip → Use state: started plus enabled: true in a normal task for the "ensure running" part.

All Ansible questions Roadmap: Ansible

More on Playbook Design, Handlers and Idempotency