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!
On Wednesday, March 26, 2014 9:14:51 AM UTC-5, James Tanner wrote:
>
> 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.
>
> On 03/26/2014 09:53 AM, Mark Casey wrote:
>
> 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:
>>
>> You can see links to the documentation for the ID here:
>>
>> 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.
>>
>>
>>
>>
>> On Fri, Mar 7, 2014 at 6:39 PM, Mark Casey <[email protected]> wrote:
>>
>>> 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
>>> --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/c4289ff8-74fb-4b7b-8cfb-84d9516b9b35%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/c4289ff8-74fb-4b7b-8cfb-84d9516b9b35%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> 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 [email protected] <javascript:>.
> To post to this group, send email to [email protected]<javascript:>
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/13ec338a-eb64-46db-9262-aa0b7da1871a%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/13ec338a-eb64-46db-9262-aa0b7da1871a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/cf52e04f-2e79-4e6c-80f1-c15e21bde924%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.