Interview Prep/Ansible/Ad-hoc Commands, Modules and Idempotency

Why prefer a dedicated module over `shell`/`command`?

BeginnerConceptAd-hoc Commands, Modules and Idempotency
Answer

Modules check state before acting, report changed accurately, support check and diff mode, return structured data, handle platform differences and escape arguments safely. A shell: apt install nginx always reports changed and fails ugly on a RHEL host, whereas ansible.builtin.package works on both and does nothing the second time.

When no module exists, wrap the command with creates/removes/changed_when so it is still safe to re-run.

All Ansible questions Roadmap: Ansible

More on Ad-hoc Commands, Modules and Idempotency