I am trying to create a role for aws vpc creation. one of the task is to create an elastic ip address and associate that ip address to nat gateway instance. if i run multiple times playbook it is recreating elastic ip but i would like to find a viable solution to make it idempotent. Please can you let me know if any solution. I appreciate your feeedback.
ec2_eip and ec2_vpc_nat_gateway modules is been used.
Sample code:
-
name: Create elastic ip for NAT Gateway
ec2_eip:
region: “{{ region }}”
state: “present”
register: ec2_eip -
name: Create NAT Gateway
ec2_vpc_nat_gateway:
state: “present”
if_exist_do_not_create: “true”
allocation_id: “{{ ec2_eip.allocation_id }}”
region: “{{ region }}”
Thanks in Advance