- name: Launch instances
gce:
instance_names: abc
network: dfe
machine_type: "{{ machine_type }}"
image: "{{ image }}"
zone: "{{ zone }}"
tags: test
register: gce
- name: run python script to make ip static
script: python script that may or may not change the ip
register: res
failed_when: "res.rc == 1"
changed_when: "res.rc == 0"
with_items: gce.instance_data
- name: Add instance to local host group
local_action: lineinfile dest=hosts insertafter="\[gce\]" line="{{ item.public_ip }} ansible_ssh_private_key_file=~/.ssh/google_compute_engine" state=present
with_items: gce.instance_data
However, the public_ip may have changed so how can I update it before I try to add the item to the "hosts" file?