Google cloud platform 将GCE元数据用作可解释的事实或变量

Google cloud platform 将GCE元数据用作可解释的事实或变量,google-cloud-platform,ansible,google-compute-engine,ansible-facts,Google Cloud Platform,Ansible,Google Compute Engine,Ansible Facts,我需要访问Google Compute Engine实例元数据(实例名称、区域、项目名称、机器类型、自定义元数据、外部ip等),其形式为可解析事实/变量。例如,我希望能够使用一个变量/事实,如:{{gce_fact_instance_name}},当ansible从每个主机收集事实时,它将从实例中收集(因为所有实例都可以访问自己的元数据) 我找到了这个模块,但它似乎不是当前开发的,并且在尝试使用它时会产生错误 上面列出的模块的作者修复了这个错误,他的模块非常有用,并且完全满足了我的需要。示例代码

我需要访问Google Compute Engine实例元数据(实例名称、区域、项目名称、机器类型、自定义元数据、外部ip等),其形式为可解析事实/变量。例如,我希望能够使用一个变量/事实,如:{{gce_fact_instance_name}},当ansible从每个主机收集事实时,它将从实例中收集(因为所有实例都可以访问自己的元数据)


我找到了这个模块,但它似乎不是当前开发的,并且在尝试使用它时会产生错误

上面列出的模块的作者修复了这个错误,他的模块非常有用,并且完全满足了我的需要。示例代码如下:

- 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 }}"