The Rackspace module and dynamic inventory in recent versions of Ansible (I use 1.4.1) allow you to group servers!
The rax module accepts the "group" parameter, which is stored in the metadata of the created server, which the Rackspace dynamic inventory plugin will then extract to create Ansible groups , so subsequent games can use the group names you specify.
However, it seems that inventory is only requested at the beginning of the game. To work with recently launched servers within the same startup, you need to use the add-host module to add them to your 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
Here 's an AWS entry for this that covers many of the same high-level concepts, even if the vendor is different.
source share