簡體   English   中英

將GCE元數據用作敏感事實或變量

[英]Using GCE metadata as ansible facts or variables

我需要以ansible事實/變量的形式訪問Google Compute Engine實例元數據(實例名稱,區域,項目名稱,計算機類型,自定義元數據,外部IP等)。 例如,我希望能夠使用像{{gce_fact_instance_name}}這樣的變量/事實,當ansible從每個主機收集事實時,它將從實例中收集(因為所有實例都可以訪問其自己的元數據)。

我找到了這個模塊,但是它似乎不是當前開發的,並且在嘗試使用它時會產生一個錯誤。 https://github.com/br0ziliy/ansible-module-gce-facts

上面列出的模塊的作者解決了該錯誤,他的模塊非常有用,並且確實滿足了我的需要。 下面的示例代碼:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM