A few observations inline:
Here you explicitly decrease the wait_timeout by 100 seconds (default = 600).
This may cause the instance(s) to be not ready yet, which in turn
might cause the error.
Suggestion: either use the default (i.e. do not define wait_timeout),
or use a higher value - to increase the likelihood that all instances
are in the state that you want them to be.
While we're on that topic - you didn't define this desired state, so
the default ('present') is used:
https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_instance_module.html#parameter-state
If you spin up new instances, state 'present' means just that - it's
there. But it might or might not have all of its network interfaces
added and/or configured.
> volumes:
> - device_name: /dev/xvda
> ebs:
> volume_type: gp3
> volume_size: 20
> delete_on_termination: yes
> vpc_subnet_id: xxxxxxxxxxxx
> network:
> assign_public_ip: no
> security_groups: ["xxxxxxxxxx", "xxxxxxxxxxx", "xxxxxxxxxxxxxx"]
> tags:
> Enviroment: TEST
> count: 1
> - name: Pause Few Seconds
> pause:
> seconds: 20
> prompt: "Please wait"
Here you seem to work around the unstable 'present' state that you
implicitly required in the previous task?
> - name: Get Information for EC2 Instances
> ec2_instance_info:
> region: us-east-1
> filters:
> "tag:Name": new-{{ CARRIER }}.test
> register: ec2_metadata
> - name: Parse JSON
> set_fact:
> ip_addr: "{{ ec2_metadata.instances[0].network_interfaces[0].private_ip_address }}"
>
> Any help, please?
1. Drop the entire pause task
2. Drop the entire ec2_instance_info task
3. Remove the 'wait_timeout' parameter from the ec2_instance task
4. Add a state parameter with value 'running' to the ec2_instance task
5. Register the output of the ec2_instance task in a variable (say
'my_instances')
6. Add a debug task for the my_instances variable. This should have
the information you are looking for. Based on the exact structure of
that you can select the required keys/indices (or use json_query etc)
Dick