Can I remove past ec2 idempotency/request ids??

109 views
Skip to first unread message

Mark Casey

unread,
Mar 7, 2014, 7:39:01 PM3/7/14
to ansible...@googlegroups.com
Hello,

When creating ec2 instances we have the "id" field for idempotency. I was wondering how long previously-used ids linger for and, if they auto-prune, whether they can be removed early/manually.

Thank you,
Mark

Michael DeHaan

unread,
Mar 7, 2014, 9:26:58 PM3/7/14
to ansible...@googlegroups.com
You can see links to the documentation for the ID here:


However, a better way to do it is to use the "exact_count" parameter and specify a tag.

We should likely mark the id field in the documentation as legacy and non-preferred.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c4289ff8-74fb-4b7b-8cfb-84d9516b9b35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Casey

unread,
Mar 8, 2014, 12:23:59 PM3/8/14
to ansible...@googlegroups.com
Thanks, and sorry! I'd seen that page some time ago but iirc it has more info than before and I didn't think to recheck it.

Will definitely be switching to exact_count as well.

Thanks again,
Mark

Mark Casey

unread,
Mar 26, 2014, 9:53:13 AM3/26/14
to ansible...@googlegroups.com
Okay, so in the interest of moving to exact_count I switched from:

- name: Set up a new host instance on EC2
  ec2: >
   region="{{ ec2vars.region }}"
   zone="{{ ec2vars.zone }}"
   id="{{ serverPod + '_' + type }}"
   ec2_access_key="{{ ec2vars.ec2_access_key }}"
   ec2_secret_key="{{ ec2vars.ec2_secret_key }}"
   key_name="{{ ec2vars.key_name }}"
   instance_type="{{ ec2vars.instance_type }}"
   image="{{ ec2vars.image }}"
   group="{{ ec2vars.group }}"
   wait="{{ wait }}"
   wait_timeout=600
   user_data="{{ type }}"
   instance_tags='{"ec2serverPod":"{{ serverPod }}", "ec2type":"{{ type }}", "ec2serverPod_and_ec2type":"{{ serverPod }}_{{ type }}", "provisioned":"False", "Name":"{{ virtualhostFullName }}_{{ type }}"}'
   count="{{ count }}"
   vpc_subnet_id="{{ ec2vars.vpc_subnet_id }}"
  register: ec2

to:

- name: Set up a new host instance on EC2
  ec2: >
   region="{{ ec2vars.region }}"
   zone="{{ ec2vars.zone }}"
   ec2_access_key="{{ ec2vars.ec2_access_key }}"
   ec2_secret_key="{{ ec2vars.ec2_secret_key }}"
   key_name="{{ ec2vars.key_name }}"
   instance_type="{{ ec2vars.instance_type }}"
   image="{{ ec2vars.image }}"
   group="{{ ec2vars.group }}"
   wait="{{ wait }}"
   wait_timeout=600
   user_data="{{ type }}"
   instance_tags='{"ec2serverPod":"{{ serverPod }}", "ec2type":"{{ type }}", "ec2serverPod_and_ec2type":"{{ serverPod }}_{{ type }}", "provisioned":"False", "Name":"{{ virtualhostFullName }}_{{ type }}"}'
   exact_count="{{ count }}"
   count_tag="ec2serverPod_and_ec2type":"{{ serverPod }}_{{ type }}"
   vpc_subnet_id="{{ ec2vars.vpc_subnet_id }}"
  register: ec2

but I seem to have lost idempotence because I get new instances every time it runs. I've since reformatted it to drop the quoted block and make it look more like the docs but there was no improvement:

- name: Set up a new host instance on EC2
  local_action:
    module: ec2
    region: "{{ ec2vars.region }}"
    zone: "{{ ec2vars.zone }}"
    ec2_access_key: "{{ ec2vars.ec2_access_key }}"
    ec2_secret_key: "{{ ec2vars.ec2_secret_key }}"
    key_name: "{{ ec2vars.key_name }}"
    instance_type: "{{ ec2vars.instance_type }}"
    image: "{{ ec2vars.image }}"
    group: "{{ ec2vars.group }}"
    wait: "{{ wait }}"
    wait_timeout: 600
    user_data: "{{ type }}"
    instance_tags: '{"ec2serverPod":"{{ serverPod }}", "ec2type":"{{ type }}", "ec2serverPod_and_ec2type":"{{ serverPod }}_{{ type }}", "provisioned":"False", "Name":"{{ virtualhostFullName }}_{{ type }}"}'
    exact_count: "{{ count }}"
    count_tag: ec2serverPod_and_ec2type:"{{ serverPod }}_{{ type }}"
    vpc_subnet_id: "{{ ec2vars.vpc_subnet_id }}"
  register: ec2

Anyone see anything obvious with that last example? Do I have to list all of the instance's tags in count_tag?

Thank you,

Mark


On Friday, March 7, 2014 8:26:58 PM UTC-6, Michael DeHaan wrote:

James Tanner

unread,
Mar 26, 2014, 10:14:51 AM3/26/14
to ansible...@googlegroups.com
I would first try to make the instance_tags a dictionary instead of a "dictionary-like" string:

instance_tags:
    foo: bar
    baz: bang
    who: doo

And use the same pattern for the count tag.

Mark Casey

unread,
Mar 26, 2014, 11:30:09 AM3/26/14
to ansible...@googlegroups.com
I had to leave one of the tags out of count_tag since it just indicates whether the host has been "provisioned" by our definition, and I was getting new instances again when it changed. So I didn't have to do the whole set of tags, but adding the balance of them in the format you suggested appears to have worked! Thanks!

I did also have to change some tasks' "with_items: ec2.instances" to "with_items: ec2.tagged_instances" to correct errors to the effect of:
TASK: [ec2/ec2_add | Add new instance(s) to group "ec2hosts"] ***************** 
fatal: [localhost] => One or more undefined variables: 'unicode object' has no attribute 'private_dns_name'

(and that's a logical progression. I'm just mentioning it here in case it helps someone switching over in the future.)

Thanks again!
Reply all
Reply to author
Forward
0 new messages