【问题标题】:Using GCE metadata as ansible facts or variables使用 GCE 元数据作为 ansible 事实或变量
【发布时间】:2018-05-24 07:08:57
【问题描述】:

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

我找到了这个模块,但它目前似乎没有开发,并且在尝试使用它时会产生错误。 https://github.com/br0ziliy/ansible-module-gce-facts

【问题讨论】:

    标签: google-cloud-platform ansible google-compute-engine ansible-facts


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      • 2021-10-19
      • 2017-10-16
      • 2016-08-08
      • 1970-01-01
      • 2017-01-29
      相关资源
      最近更新 更多