host selection based on host variables

Hey Guys,

Was just going through the ec2.py inventory plugin, and it seems like a pretty useful thing. Is it possible in ansible to select hosts to execute on based on the host vars? For example: “ansible instance_type=m1.small ping” should ping all the m1.small instances in my inventory.

Pardeep,

The ec2.py script could be modified to generate dynamic groups based
on the instance_type. Then you could run the play against that group.

- James

Yep, that certainly is an option. But if it could be performed at the vars level then one could use “ohai” or “facter” generated data also. It seems conceptually in ansible vars are only supposed to be used in playbooks. Please correct me if I am wrong here.

Just realised that what I am talking about here would require a core change in the way ansible executes modules on the remote machine. Sorry for my previous email.

Pradeep Jindal wrote:

Hey Guys,

Was just going through the ec2.py inventory plugin, and it seems like a
pretty useful thing. Is it possible in ansible to select hosts to execute
on based on the host vars? For example: "ansible instance_type=m1.small
ping" should ping all the m1.small instances in my inventory.

This is what group_by is for, creating groups based on your variables.
However, in this case it isn't necessary, as the ec2 inventory plugin already
creates a type_m1_small group containing all of your m1.small instances.

Daniel

Ah! alright. How can I use group_by module from command line to “ping” all “x86_64” hosts in my inventory? Or is it that I will have to write a playbook like https://github.com/ansible/ansible/blob/devel/examples/playbooks/group_by.yml for doing the same?