Rax module

Hi,

We’ve run into a problem with the rax module. It worked fine to create our test env, but when we came to creating the prod version, it didn’t do anything. (No errors, but no changes either). Our incantation looks like this:

  • name: App servers
    rax:
    args:
    credentials: ~/.rackspace_cloud_credentials
    region: “{{ region }}”
    name: “app-{{ target_environment }}-{{ region }}-%02d”
    count: “{{ app_server_count }}”
    exact_count: yes
    group: app_servers
    flavor: performance1-1

image: 11b0cefc-d4ec-4f09-9ff6-f842ca97987c
state: present
wait: yes

wait_timeout: 900

The problem seems to be that we’re using the same group for both sets of servers. The code here doesn’t check that the name pattern matches before adding it to the list of servers. I guess my question is: is this a bug, or are we using it wrong?

Thanks,

Graham

This is probably a better discussion for the ansible-project list instead of devel, but since it is here, I’ll go ahead and answer.

To directly address your question: I do not see it as a bug, and you are not using it wrong, you just haven’t been fully educated on the module.

The rax module looks at a few things for idempotency in your case:

  1. region
  2. group
  3. count
  4. exact_count

You are correct that the name is not considered in this scenario. I see that you have a few options to get this to do what you want:

  1. use different accounts for dev/stg/prod
  2. use different regions for dev/stg/prod
  3. use different ‘group’ configurations

I’ll talk a little about #3 since 1 and 2 are somewhat simple enough to implement. This will also include info about using rax.py as an inventory script incase you are doing so.

The ‘group’ configuration is primarily used for idempotent operations when creating servers. I would recommend applying an ‘environment’ identifier to your ‘group’ such as:

group: app_servers_prod

Now assuming you are using rax.py and still want to be able to target ‘app_servers’, you can add something such as:

meta:
groups:

  • app_servers

  • prod

Those servers will be grouped in 3 groups: app_servers_prod, app_servers and prod. rax.py looks at both the ‘group’ and ‘groups’ metadata for creating groups. ‘group’ is just a single simple string. ‘groups’ can be specified as either a list or a comma separated string. The rax module automatically handles lists by turning them into comma separated strings for you, I just find it easier to look at it in list form. rax.py will split on commas in ‘groups’ and create individual inventory groups for each one.

Putting it all back together using your example:

  • name: App servers
    rax:
    credentials: ~/.rackspace_cloud_credentials
    region: “{{ region }}”
    name: “app-{{ target_environment }}-{{ region }}-%02d”
    count: “{{ app_server_count }}”
    exact_count: yes
    group: “app_servers_{{ target_environment }}”
    meta:
    groups:
  • app_servers
  • “{{ target_environment }}”
    flavor: performance1-1

image: 11b0cefc-d4ec-4f09-9ff6-f842ca97987c
state: present
wait: yes

wait_timeout: 900

That should achieve what you are looking to do.

Don’t worry, I’m quite happy to be told I’m doing it wrong :slight_smile:

You’ve pointed out the fatal flaw in the plan, we need to have separate groups per env to be able to address just those servers. We’re going to switch to “{{ target_environment }}_app_servers”. Thanks.

Btw, it would be good to have that bit about the meta groups in the docs, I had to work it out for myself by digging through rax.py. Also, I have another question, but I’ll use the other list.

Thanks again,

Graham