That... makes sense.  I should have ctrl-f 'idempotency' on the module 
documentation.  I'll give it a try, thanks for the help!

On Wednesday, May 5, 2021 at 11:49:18 PM UTC-7 dick....@geant.org wrote:

> You should supply an 'id' parameter:
>
>
> https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_module.html#parameter-id
>
>
> On Thu, 6 May 2021 at 00:22, Dave York <dave...@gmail.com> wrote:
>
>> Hi ansible squad!
>>
>> I've been using amazon.aws.ec2 (or community.aws.ec2_instance - ive been 
>> switching back and forth) to ensure there is an ec2 instance created for 
>> each {{ inventory_hostname }} by using tags.  It doesn't seem to work.  
>>
>> Every time I run the playbook with the below play, it just creates a new 
>> ec2 instance?  How can I make it more idempotent? If the instance already 
>> exists, dont create a new one?
>>
>> Preferably without other plays? 
>>
>>   - name: Ensure EC2 instance exists
>>     amazon.aws.ec2:
>>       aws_access_key: '{{ aws_access_key }}'
>>       aws_secret_key: '{{ aws_secret_key }}'
>>       region: '{{ aws_region }}'
>>       image: '{{ aws_ec2_ami }}'
>>       instance_type: '{{ aws_instance_type_web }}'
>>       vpc_subnet_id: '{{ aws_subnet_id }}'
>>       group: 'SG-{{ environment_designator }}'
>>       key_name: 'Keypair-{{ environment_designator }}'
>>       instance_tags:
>>         Mytag.MyEnvironment: ""
>>         Mytag.MyEnvironment.Environment: '{{ environment_designator }}'
>>         Mytag.MyEnvironment.Roles: web1
>>         Mytag.MyEnvironment.Hostname: '{{ inventory_hostname }}'
>>       wait: yes
>>       assign_public_ip: no
>>     register: ec2_instances
>>     delegate_to: localhost
>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/d8aedb06-f63e-4ebc-8dd6-8134b72a1a07n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/d8aedb06-f63e-4ebc-8dd6-8134b72a1a07n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> -- 
> Sent from a mobile device - please excuse the brevity, spelling and 
> punctuation.
>

-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/12b90a50-7649-4929-8d19-97ec221907d8n%40googlegroups.com.

Reply via email to