【发布时间】:2017-09-08 00:58:33
【问题描述】:
我有以下 Ansible 代码,它从 azure 中的“az”命令读取输入。我基本上想用它来查看资源组何时完成创建我的 VMS。
#!/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"
}
]
}
所以基本上我想获取每个项目的 properties.Provisioningstate(成功与否)。即使我试图勇敢地这样做,我也无法对这些进行映射。
ansible 的输出转换为 JSON,但我无法选择或映射属性。我总是收到关于各种无法正常工作的错误(也就是找不到属性等等)。
主要错误是我每次都无法提取provisioningstatus.properties.provisioningState,我收到“未定义变量”消息。
ok: [localhost] => {
"provisioningstatus.properties": "VARIABLE IS NOT DEFINED!"
}
【问题讨论】:
-
你能把这里的示例输出替换为一个显示
provisioningstatus变量内容的ansibledebug任务的输出吗?您能否准确地展示您遇到的故障类型(具体的错误消息和生成它们的任务)? -
我会这样做的。大约一个小时后可以完成一些操作
-
完成。我已按要求更新了问题。