AWS tagging needed to work dynamically with Rackspace instances?

Hi,

Will Thames has written very helpfully (for me) on how to use Ansible to interact with newly provisioned EC2 servers dynamically.

I’d like to dupe Will’s approach for some other cloud providers, or at least, Rackspace.

Following willthames.github.io/2014/03/17/ansible-layered-configuration-for-aws.html:

  1. include the following in a ec2 module create play:
instance_tags: 
        name: "{{inventory_hostname}}
  1. interact with the fresh instance later with a command like…
EC2_INI_PATH=./ec2.ini ansible-playbook -i ~/src/ansible/plugins/inventory/ec2.py -e instance=prod-web-server-78a ec2-facts.yml

…where ec2-facts.yml is something like…

- hosts: tag_name_{{instance}}

  tasks:
  - name: get EC2 facts
    action: ec2_facts
  1. I do not understand how his hosts variable in the ec2-facts.yml works

  2. By what principle could I individuate servers instantiated on other cloud providers in similar manner?
    Thanks,

G

I’m not entirely sure I follow what you are having problems with, so I may only be able to really answer #1 right now.

{{instance}} is provided on the command line in that example with “-e instance=prod-web-server-78a” That is where the variable comes from.

This is a little different from Rackspace, in that all instances already have names, so there is no need to specifically target a tag/meta item (although you could) to reach a server. You can simply use the actual name you have given an instance. When you create an instance via the rax module, there is an explicit ‘name’ parameter.

So maybe instead of “hosts: tag_name_{{instance}}” you could just do “hosts: {{instance}}” where instance is the actual name of the instance.

Does this answer your questions?

Also, for Rackspace, there is a rax_facts module, and a rax.py inventory script. The rax_facts module works slightly different than the ec2_facts, so make sure you check the documentaiton.

So maybe instead of “hosts: tag_name_{{instance}}” you could just do “hosts: {{instance}}” where instance is the actual name of the instance.

Yes, that does it: I can interact now dynamically with Rackspace.

If my question was unclear, I think it’s because I thought “tag_name_” in…

- hosts: tag_name_{{instance}}

…was something from Ansible, whereas, it would appear it is specific to AWS.

Thanks,

G

Will has done some good things for us but I’m confused a bit why an AWS example is using static inventory at all :slight_smile:

"

  1. I do not understand how his hosts variable in the ec2-facts.yml works"