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.
More on Playbook Design, Handlers and Idempotency
Your playbook reports `changed` on every run for a task that runs a shell command. How do you fix it?BeginnerNginx must reload only when its config file actually changes.BeginnerA task fails halfway and its handler never ran, but the config file was changed. The next run shows no change and the service never reloads.AdvancedYou need three tasks to notify one handler, and want it to run once. Is that automatic?BeginnerYou need to deploy a binary only if it is missing or its checksum differs.IntermediateHow do you safely edit one line in `/etc/ssh/sshd_config` and be sure SSH keeps working?Intermediate