Can I create host group aliases when using EC2 inventory?

Hi,

I’ve got an existing inventory file that hard-codes our EC2 hosts. I’m trying to move over to the dynamic inventory, using tags. The problem I have is that all my roles refer to hosts such as ‘webservers’, ‘logstash’ etc. and the EC2 dynamic inventory groups look like ‘tag_class_webservers’ etc.

I’d like to be able to tell ansible to create a host group called ‘webservers’ containing every instance tagged ‘tag_class_webservers’ (or simply aliases to it), so that I don’t have to modify all my playbooks to work with the dynamic inventory. Is there a way to do this?

add_host: name={{ item }} groups=webservers
with_items: groups['tag_class_webservers']

Something along those lines should help you.

-jlk

This is more of a general question than a -devel topic, but what Jesse noted above should work. However, if you’ve specified the tags when creating those instances and are using the ec2.py inventory script those should be picked up automatically.

The one caveat for both situations though, is that the set of hosts being operated on currently will not change - you have to create another play (within the same playbook) to pick up the new hosts.

I’ve specified the tags and the ec2 inventory is working. I guess what I really want is an inventory that says ‘take an input inventory and augment it’. Inventory inheritance :slight_smile:

WRT to asking on the wrong list, sorry about that. I thought it was a little weird - I followed the ‘User Mailing List’ link on http://docs.ansible.com/faq.html#i-don-t-see-my-question-here

Possibly that link should go to https://groups.google.com/forum/#!forum/ansible-project instead?

Thanks,
-Darren

Indeed it should, can you please file a ticket at github.com/ansible/ansible about the link, or otherwise send us a patch for the documentation page?

Thanks!