azureの 'az'コマンドから入力を読み込む以下のAnsibleコードがあります。基本的には、VMSの作成が完了したリソースグループを確認するために使用します。ここでシェルプログラムからのjson出力を解析するために、コマンドモジュールを使用してください。
#!/usr/local/bin/ansible-playbook
---
- name: Firewall Rules
hosts: localhost
connection: local
vars:
iscbr: false
tasks:
- name: Register status of group x
command: az group deployment list -g Tes1Pod
register: azdeployment
- name:
set_fact:
provisioningstatus: "{{ (azdeployment.stdout|from_json) }}"
- name: debug provisioningstatus
debug:
var: "{{item}}"
with_items: "{{provisioningstatus.properties}}"
# - name: Debug stuff
# debug:
# msg: " item.provisioningState"
# with_items: "{{provisioningstatus"
# - debug: var=provisioningstatus
ok: [localhost] => {
"provisioningstatus": [
{
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Resources/deployments/vm_deploy_xxxxxxxx",
"name": "vm_deploy_xxxxxxxx",
"properties": {
"correlationId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"debugSetting": null,
"dependencies": [
{
"dependsOn": [
{
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Network/networkSecurityGroups/gtsNSG",
"resourceGroup": "Tes1Pod",
"resourceName": "gtsNSG",
"resourceType": "Microsoft.Network/networkSecurityGroups"
},
{
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Network/publicIPAddresses/gtsPublicIP",
"resourceGroup": "Tes1Pod",
"resourceName": "gtsPublicIP",
"resourceType": "Microsoft.Network/publicIPAddresses"
}
],
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Network/networkInterfaces/gtsVMNic",
"resourceGroup": "Tes1Pod",
"resourceName": "gtsVMNic",
"resourceType": "Microsoft.Network/networkInterfaces"
},
{
"dependsOn": [
{
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Network/networkInterfaces/gtsVMNic",
"resourceGroup": "Tes1Pod",
"resourceName": "gtsVMNic",
"resourceType": "Microsoft.Network/networkInterfaces"
}
],
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Compute/virtualMachines/gts",
"resourceGroup": "Tes1Pod",
"resourceName": "gts",
"resourceType": "Microsoft.Compute/virtualMachines"
}
],
"mode": "Incremental",
"outputs": {},
"parameters": {},
"parametersLink": null,
"providers": [
{
"id": null,
"namespace": "Microsoft.Network",
"registrationState": null,
"resourceTypes": [
{
"aliases": null,
"apiVersions": null,
"locations": [
"eastus2"
],
"properties": null,
"resourceType": "networkSecurityGroups"
},
{
"aliases": null,
"apiVersions": null,
"locations": [
"eastus2"
],
"properties": null,
"resourceType": "publicIPAddresses"
},
{
"aliases": null,
"apiVersions": null,
"locations": [
"eastus2"
],
"properties": null,
"resourceType": "networkInterfaces"
}
]
},
{
"id": null,
"namespace": "Microsoft.Compute",
"registrationState": null,
"resourceTypes": [
{
"aliases": null,
"apiVersions": null,
"locations": [
"eastus2"
],
"properties": null,
"resourceType": "virtualMachines"
}
]
}
],
"provisioningState": "Succeeded",
"template": null,
"templateLink": null,
"timestamp": "2017-09-05T19:42:14.572793+00:00"
},
"resourceGroup": "Tes1Pod"
},
{
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Resources/deployments/vm_deploy_xxxxxxxxxxxxxxxx",
"name": "vm_deploy_xxxxxxxxxxxxxxxx",
"properties": {
"correlationId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"debugSetting": null,
"dependencies": [
{
"dependsOn": [
{
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Network/networkSecurityGroups/cbrNSG",
"resourceGroup": "Tes1Pod",
"resourceName": "cbrNSG",
"resourceType": "Microsoft.Network/networkSecurityGroups"
},
{
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Network/publicIPAddresses/cbrPublicIP",
"resourceGroup": "Tes1Pod",
"resourceName": "cbrPublicIP",
"resourceType": "Microsoft.Network/publicIPAddresses"
}
],
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Network/networkInterfaces/cbrVMNic",
"resourceGroup": "Tes1Pod",
"resourceName": "cbrVMNic",
"resourceType": "Microsoft.Network/networkInterfaces"
},
{
"dependsOn": [
{
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Network/networkInterfaces/cbrVMNic",
"resourceGroup": "Tes1Pod",
"resourceName": "cbrVMNic",
"resourceType": "Microsoft.Network/networkInterfaces"
}
],
"id": "/subscriptions/redacted/resourceGroups/Tes1Pod/providers/Microsoft.Compute/virtualMachines/cbr",
"resourceGroup": "Tes1Pod",
"resourceName": "cbr",
"resourceType": "Microsoft.Compute/virtualMachines"
}
],
"mode": "Incremental",
"outputs": {},
"parameters": {},
"parametersLink": null,
"providers": [
{
"id": null,
"namespace": "Microsoft.Network",
"registrationState": null,
"resourceTypes": [
{
"aliases": null,
"apiVersions": null,
"locations": [
"eastus2"
],
"properties": null,
"resourceType": "networkSecurityGroups"
},
{
"aliases": null,
"apiVersions": null,
"locations": [
"eastus2"
],
"properties": null,
"resourceType": "publicIPAddresses"
},
{
"aliases": null,
"apiVersions": null,
"locations": [
"eastus2"
],
"properties": null,
"resourceType": "networkInterfaces"
}
]
},
{
"id": null,
"namespace": "Microsoft.Compute",
"registrationState": null,
"resourceTypes": [
{
"aliases": null,
"apiVersions": null,
"locations": [
"eastus2"
],
"properties": null,
"resourceType": "virtualMachines"
}
]
}
],
"provisioningState": "Succeeded",
"template": null,
"templateLink": null,
"timestamp": "2017-09-05T19:42:11.590506+00:00"
},
"resourceGroup": "Tes1Pod"
}
]
}
。私は勇敢にそうしようとしているにもかかわらず、これらをマップすることはできない。
パブリッシャーからの出力はJSONに変換されますが、属性を選択またはマップすることはできません。私はいつも働いていない様々な事柄についてエラーを出します(別名では財産を見つけることができません)。
「定義されていない変数」というメッセージが表示されるたびに、主なエラーは単にprovisioningstatus.properties.provisioningStateを抽出できません。
ok: [localhost] => {
"provisioningstatus.properties": "VARIABLE IS NOT DEFINED!"
}
このサンプル出力を、 'provisioningstatus'変数の内容を示す可能な' debug'タスクの出力に置き換えることはできますか?また、発生しているエラーの種類(特定のエラーメッセージとそれを生成するタスク)を正確に表示できますか? – larsks
私はそれを行います。約1時間後に従うようになる人もいます。 –
完了。私は尋ねられたように質問を更新しました。 –