The Rackspace module and dynamic inventory in recent versions of Ansible (I'm using 1.4.1) do let you group servers!
The rax
module accepts a "group" parameter that's stored in the created server's metadata, which the Rackspace dynamic inventory plugin will then extract to create Ansible groups, so subsequent plays can use the group names that you've specified.
However, it looks like the inventory is only queried at the start of the play. To work with your newly launched servers within the same run, you'll need to use the add-host module to add them to the inventory at runtime:
- name: build webservers
local_action:
module: rax
name: webserver
group: webservers
exact_count: true
credentials: ~/.rackspace_cloud_credentials
flavor: 2
image: df27d481-63a5-40ca-8920-3d132ed643d9
files:
/root/.ssh/authorized_keys: ~/.ssh/id_rsa.pub
state: present
disk_config: manual
wait: yes
wait_timeout: 10000
register: webserversvar
- name: add newly provisioned webservers to a group
local_action: add_host hostname={{ item.accessIPv4 }} groupname=webservers
with_items: webserversvar.instances
- name: build databases
local_action:
module: rax
name: database
group: databases
exact_count: true
credentials: ~/.rackspace_cloud_credentials
flavor: 2
image: df27d481-63a5-40ca-8920-3d132ed643d9
files:
/root/.ssh/authorized_keys: ~/.ssh/id_rsa.pub
state: present
disk_config: manual
wait: yes
wait_timeout: 10000
register: databasesvar
- name: add newly provisioned databases to a group
local_action: add_host hostname={{ item.accessIPv4 }} groupname=databases
with_items: databasesvar.instances
There's a writeup about doing this on AWS which covers a lot of the same high-level concepts, even though the provider is different.