The goal is to limit the group of hosts a play inside a playbook is run on. The below code doesn't limit the groups to group cluster and sometimes the below playbook is run on localhost
- hosts: all:!localhost
gather_facts: no
tasks:
...
The inventory file is below:
[localhost]
127.0.0.1 ansible_connection=local
[cluster]
ip1
ip2
ip3
Tried - hosts: cluster
, however, play still runs on localhost
sometimes.
There's option to limit the groups via cli:
ansible-playbook playbooks/PLAYBOOK_NAME.yml --limit 'all:!localhost'
My goal is to limit groups a play is run on from the playbook source code.