Reputation: 835
I have an inventory file
example:
[groupa]
10.102.16.100
10.102.16.101
[groupa:vars]
app=testapp-a
env=staging
[groupb]
10.102.16.102
10.102.16.103
[groupb:vars]
app=testapp-b
env=production
Now if I run
ansible-playbook -i ./example playbook-x.yml
This will run for all the hosts. Is there any way I can specify the group name in the command line itself.
I'm expecting something like
ansible-playbook -i ./example --group-name groupb playbook-x.yml
Upvotes: 3
Views: 8027
Reputation: 33
I think you want to target inventory groups dynamically; a simple approach is to pass the hosts as variable in the playbook.
---
hosts: “{{target}}”
tasks:
While running the playbook pass the target variable like ‘ansible-playbook playbook-x.yml -i ./example -e target=groupa’
Upvotes: 3