1
votes

I need access to Google Compute Engine Instance metadata (instance name, zone, project name, machine type, custom metadata, external-ip, etc) in the form of ansible facts/variables. For example, I'm hoping to be able to use a variable/fact like: {{ gce_fact_instance_name }} which would be gathered from the instance when ansible is gathering facts from each host (because all instances have access to their own metadata).

I found this module but it appears to not be currently developed, and it produces an error when trying to use it. https://github.com/br0ziliy/ansible-module-gce-facts

1

1 Answers

2
votes

The author of the module listed above fixed the error, and his module is incredibly useful, and does exactly what I need it to. Sample code below:

- name: Gather instance GCE facts
  action: gce_facts

- name: Update GCE labels
  local_action:
    module: gce_labels
    project_id: "{{ ansible_gce.project.projectId }}"
    resource_type: instances
    resource_name: "{{ ansible_gce.instance.name }}"
    resource_location: "{{ ansible_gce.instance.zone }}"
    #ld_ variables are custom variables we use for system management
    labels:
      env: "{{ ld_env }}"
      product: "{{ ld_product }}"
      role: "{{ ld_role }}"