
A good way to explicitly and dynamically control which inventory hosts or groups a playbook executes against is by defining the host’s field in the playbook as a variable, commonly named “target”.
---
- name: Upgrade software.
hosts: "{{ target }}"
roles:
- jiholland.cisco.software
This variable is then defined as an extra vars each time you run the playbook, and if you forget it the playbook will fail immediately as hosts are a required playbook attribute.
$ ansible-playbook software_playbook.yml -e "target=switch1,switch2"
In this example, the playbook is executed on switch1 and switch2 from your inventory.
Leave a Reply