Adding instances to multiple host groups using the Ansible rax module

We use the Ansible rax module to create new instances of our “cloud servers”. It’s pretty easy to add them to one group:

- name: Build a Cloud Server
  tasks:
      local_action:
        module: rax
        name: rax-test1
        wait: yes
        state: present
        networks:
          - private
          - public
        group: app-servers

But it’s also quite handy to be able to place a server in multiple groups (e.g. test / production, different regions etc). There’s nothing in the documentation about this, but a bit of code spelunking reveals that a metadata key named “groups” can contain a comma-separated list of extra host groups:

- name: Build a Cloud Server
  tasks:
      local_action:
        module: rax
        name: rax-test1
        wait: yes
        state: present
        networks:
          - private
          - public
        group: app-servers
        meta:
            groups: test, london