# Can I remove past ec2 idempotency/request ids??

**URL:** <https://forum.ansible.com/t/can-i-remove-past-ec2-idempotency-request-ids/14730>\
**Category:** Ansible Project\
**Created:** [March 8, 2014, 12:39am UTC](https://forum.ansible.com/t/can-i-remove-past-ec2-idempotency-request-ids/14730 "2014-03-08T00:39:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Casey](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mark\_Casey](https://forum.ansible.com/u/Mark_Casey)\
**Post date:** [March 8, 2014, 12:39am UTC](https://forum.ansible.com/t/can-i-remove-past-ec2-idempotency-request-ids/14730/1 "2014-03-08T00:39:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 8, 2014, 2:26am UTC](https://forum.ansible.com/t/can-i-remove-past-ec2-idempotency-request-ids/14730/2 "2014-03-08T02:26:58Z")

</div>

You can see links to the documentation for the ID here:

[http://docs.ansible.com/ec2\_module.html](http://docs.ansible.com/ec2_module.html)

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.

---

<div class="post-metadata">

**Author:** ![Mark\_Casey](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mark\_Casey](https://forum.ansible.com/u/Mark_Casey)\
**Post date:** [March 8, 2014, 5:23pm UTC](https://forum.ansible.com/t/can-i-remove-past-ec2-idempotency-request-ids/14730/3 "2014-03-08T17:23:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mark\_Casey](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mark\_Casey](https://forum.ansible.com/u/Mark_Casey)\
**Post date:** [March 26, 2014, 1:53pm UTC](https://forum.ansible.com/t/can-i-remove-past-ec2-idempotency-request-ids/14730/4 "2014-03-26T13:53:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tannerjc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/tannerjc/32/985_2.png) [@tannerjc](https://forum.ansible.com/u/tannerjc)\
**Post date:** [March 26, 2014, 2:14pm UTC](https://forum.ansible.com/t/can-i-remove-past-ec2-idempotency-request-ids/14730/5 "2014-03-26T14:14:51Z")

</div>

I would first try to make the instance\_tags a dictionary instead of a "dictionary-like" string:

instance\_tags:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foo: bar  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;baz: bang  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;who: doo

And use the same pattern for the count tag.

---

<div class="post-metadata">

**Author:** ![Mark\_Casey](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mark\_Casey](https://forum.ansible.com/u/Mark_Casey)\
**Post date:** [March 26, 2014, 3:30pm UTC](https://forum.ansible.com/t/can-i-remove-past-ec2-idempotency-request-ids/14730/6 "2014-03-26T15:30:09Z")

</div>

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:

> ```auto
> 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!
