A role must run a task on another host, such as registering with a load balancer.
IntermediateScenarioRoles, Collections and Project Structure
Answer
Situation read → Delegation inside a role.
What I'd do →
- community.general.haproxy:
backend: web
host: "{{ inventory_hostname }}"
state: enabled
delegate_to: "{{ groups['lb'][0] }}"
Why → Variables still resolve for the original host, while the action runs on the LB.
Interview tip → Be aware ansible_* connection vars come from the delegate host in newer versions; check with -vvv.
More on Roles, Collections and Project Structure
You have a 600-line playbook that sets up web, db and monitoring. How do you restructure it?BeginnerWhere do you put a variable users of your role are expected to override?BeginnerTwo roles need to run in a fixed order, such as `common` before `nginx`.BeginnerA role is used twice with different parameters in one play, but only runs once.IntermediateYou want to share roles across several repos and teams.IntermediateHow do you pin Ansible itself so a CI run today behaves like one last month?Intermediate