2017-02-21 1 views
1

私はパブリックIPアドレスをadd_hostで使用する変数に取得しようとする場合を除いて、すべてが動作している、AnAsureでAzureの自動化のパイプラインを設定しようとしています。値が示されているようですがAnhere azure_rm_publicipaddress_factsモジュールからadd_hostで使用する変数にパブリックIPを取得する方法は?

fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined.

:私は次のエラーを与える。これにより

--- 
- name: Get Public IP 
    azure_rm_publicipaddress_facts: 
    resource_group: '{{ my_resource_group }}' 
    name: '{{ my_name }}' 
    register: azure_ip 

- debug: var=azure_ip verbosity=2 

- name: Add new instance to host group 
    add_host: 
    hostname: '{{ item.ipAddress }}' 
    groupname: launched 
    with_items: azure_ip.azure_publicipaddresses 

: はここに私の例の作業ですので

TASK [azure : debug] *********************************************************** 
task path: mytest/roles/azure/tasks/get_ip.yml:14 
ok: [localhost] => { 
    "azure_ip": { 
     "ansible_facts": { 
      "azure_publicipaddresses": [ 
       { 
        "etag": “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
        "id": "/subscriptions/0000000000000/resourceGroups/myrgrp/providers/Microsoft.Network/publicIPAddresses/my_ip_001", 
        "location": “euwest", 
        "name": “my_ip_001", 
        "properties": { 
         "idleTimeoutInMinutes": 4, 
         "ipAddress": “20.113.125.63", 
         "ipConfiguration": { 
          "id": "/subscriptions/000000000000/resourceGroups/mygrprgrp/providers/Microsoft.Network/networkInterfaces/myrgrp-nic001/ipConfigurations/default" 
         }, 
         "provisioningState": "Succeeded", 
         "publicIPAddressVersion": "IPv4", 
         "publicIPAllocationMethod": "Dynamic", 
         "resourceGuid": “fffff-4444444-cccccc" 
        }, 
        "type": "Microsoft.Network/publicIPAddresses" 
       } 
      ] 
     }, 
     "changed": false 
    } 
} 

、私は「推測します誰かが私を正しい方向に向けることができますか?

答えて

2

変更:

- name: Add new instance to host group 
    add_host: 
    hostname: '{{ item.ipAddress }}' 
    groupname: launched 
    with_items: azure_ip.azure_publicipaddresses 

へ:with_items

- name: Add new instance to host group 
    add_host: 
    hostname: "{{ item.properties.ipAddress }}" 
    groupname: launched 
    with_items: "{{ azure_ip.ansible_facts.azure_publicipaddresses }}" 
  • あなたは、いくつかのAnsibleのバージョン以降に参照さ
  • キー名を"{{ }}"に変数を含める必要が異なっているようですデバッグ出力
+0

はい、私の悪いです。それはあなたの例で動作します。ありがとう! – zozo

関連する問題