The community.aws.ec2_instance module returns facts about the ec2 including interfaces and IPs. Register these facts and you can access it.
- community.aws.ec2_instance:
aws_access_key: "{{ access_key }}"
aws_secret_key: "{{ secret_key }}"
security_token: "{{ session_token }}"
name: "{{ ec2_name }}"
key_name: "{{ ec2_key }}"
vpc_subnet_id: "{{ subnet_id }}"
security_group: "{{ secgroup_id }}"
network:
assign_public_ip: false
image_id: "{{ ami_image_id }}"
instance_type: "{{ ec2_size }}"
volumes: "{{ disk_list }}"
region: "{{ aws_region }}"
register: newec2
- set_fact:
ip_addr: newec2.instances[0].network_interfaces[0].private_ip_address