Skip to content

Instantly share code, notes, and snippets.

@s-hertel
Created February 19, 2020 14:18
Show Gist options
  • Save s-hertel/0507f07ee112cf5c99f1af1bd10d8916 to your computer and use it in GitHub Desktop.
Save s-hertel/0507f07ee112cf5c99f1af1bd10d8916 to your computer and use it in GitHub Desktop.
- debug: msg="{{ ec2 }}"
# Since you're looping over ec2 creating instances, instead of ec2.tagged_instances or ec2.instances you'll need
# to iterate over the results list created due to with_items
# Brand new instance can be accessed with either the instance_ids list, or instances list
- set_fact:
only_new_instances: "{{ ec2.results | json_query('[*].instance_ids') }}"
# New and old hosts that match the count tag are always in the tagged_instances list
- set_fact:
instances_matching_count_tag: "{{ ec2.results | json_query('[*].tagged_instances[*].id') }}"
- name: Create and associate EIP
ec2_eip:
in_vpc: yes
reuse_existing_ip_allowed: yes
state: present
region: "{{ region }}"
instance_id: "{{ item }}"
register: elastic_ip
loop: "{{ instances_matching_count_tag }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment