Interview Prep/Ansible/Playbook Design, Handlers and Idempotency

You need a task to run only the first time a server is built.

IntermediateScenarioPlaybook Design, Handlers and Idempotency
Answer

Situation read → One-time bootstrap.

What I'd do → Use a marker file with creates.

- ansible.builtin.command: /opt/bootstrap.sh
  args:
    creates: /var/lib/bootstrap.done
- ansible.builtin.file:
    path: /var/lib/bootstrap.done
    state: touch
    modification_time: preserve
    access_time: preserve

Why → creates makes the task skip once the marker exists.

Interview tip → Better still, make bootstrap itself idempotent so a marker is optional.

All Ansible questions Roadmap: Ansible

More on Playbook Design, Handlers and Idempotency