Interview Prep/Ansible/Playbook Design, Handlers and Idempotency

A task should run only on Debian-family hosts and a different one on RedHat.

BeginnerScenarioPlaybook Design, Handlers and Idempotency
Answer

Situation read → OS-conditional logic.

What I'd do →

- ansible.builtin.apt: { name: nginx, state: present }
  when: ansible_facts['os_family'] == 'Debian'
- ansible.builtin.dnf: { name: nginx, state: present }
  when: ansible_facts['os_family'] == 'RedHat'

Or just use ansible.builtin.package with a vars map for names that differ.

Why → Facts give a stable OS signal; package is the generic wrapper.

Interview tip → Use ansible_facts['...'] rather than injected ansible_os_family names.

All Ansible questions Roadmap: Ansible

More on Playbook Design, Handlers and Idempotency