【问题标题】:Unable to add extension to use Azure VM extensions using Ansible无法使用 Ansible 添加扩展以使用 Azure VM 扩展
【发布时间】:2018-02-09 03:30:06
【问题描述】:

我正在尝试将 Azure VM 扩展添加到现有的 VM。下面是我用来尝试安装 Octopus Deploy Azure 扩展的示例剧本

  - name: Install Octopus deploy tentacle 
      hosts: localhost
      gather_facts: false
      vars:
        sec: 'YK/xxxxxxxxxx/JnCsPTj4kRdsWblc='
      tasks:
      - name: Create Azure clear
        azure_rm_deployment:
        state: present
        subscription_id: 'b1514ce2-xxxx-xxxxxx-xxxxx-xxxxxx'
        client_id: 'xxxxxxx-cae7-45a3-xxxxxx-9b37bce64746'
        secret: '{{ sec }}'
        tenant: "78e60c0f-xxxx-xxxx-xxxxx-63fe13a30962"
        location: 'uk west'
        resource_group_name: 'AnsibleRG'
        template_link: https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/octopus-deploy-tentacle-windows/azuredeploy.json
  #template: "{{ lookup('file', '/etc/ansible/playbooks/OctopusDeployTentacle.json') | from_json }}"

        parameters:
          vmAdminUserName:
            value: adminUser
          vmAdminPassword:
            value: mYpAss
          vmDnsName:
            value: WinVM01
          tentacleOctopusServerUrl:
            value: https://octopus.example.com
          tentacleCommunicationMode:
            value: Listen
          tentacleApiKey:
            value: XXX-ABC-DDE-DDJD-GGGJ
          tentacleRoles:
            value: web
          tentacleEnvironments:
            value: Test
          tentaclePort:
            value: 10933

当我运行 playbook 时出现错误

“部署失败,状态码:400 和消息:根据验证程序,模板部署“ansible-arm”无效。跟踪 ID 为“c73feca6-ae2d-4c10-83a0-16be06819f5a”。查看内部错误有关详细信息。有关使用详细信息,请参阅 aka.ms/arm-deploy。

我也尝试了其他几个扩展,但总是遇到同样的错误。 有人可以指导我如何解决这个问题吗?

下面是我得到的错误的更多细节

使用 -vvvv 运行剧本后

    Using module file /usr/lib/python2.7/dist-packages/ansible/modules/cloud/azure/azure_rm_deployment.py
    <127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
    <127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
    <127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/rafid/.ansible/tmp/ansible-tmp-1518117111.96-175732666939842 `" && echo ansible-tmp-1518117111.96-175732666939842="` echo /home/rafid/.ansible/tmp/ansible-tmp-1518117111.96-175732666939842 `" ) && sleep 0'
    <127.0.0.1> PUT /tmp/tmpQY52K0 TO /home/rafid/.ansible/tmp/ansible-tmp-1518117111.96-175732666939842/azure_rm_deployment.py
    <127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/rafid/.ansible/tmp/ansible-tmp-1518117111.96-175732666939842/ /home/rafid/.ansible/tmp/ansible-tmp-1518117111.96-175732666939842/azure_rm_deployment.py && sleep 0'
    <127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/rafid/.ansible/tmp/ansible-tmp-1518117111.96-175732666939842/azure_rm_deployment.py; rm -rf "/home/rafid/.ansible/tmp/ansible-tmp-1518117111.96-175732666939842/" > /dev/null 2>&1 && sleep 0'
    The full traceback is:
      File "/tmp/ansible_PZzWZG/ansible_module_azure_rm_deployment.py", line 509, in deploy_template
        deploy_parameter)
      File "/usr/local/lib/python2.7/dist-packages/azure/mgmt/resource/resources/v2017_05_10/operations/deployments_operations.py", line 282, in create_or_update
        get_long_running_status, long_running_operation_timeout)
      File "/usr/local/lib/python2.7/dist-packages/msrestazure/azure_operation.py", line 350, in __init__
        raise CloudError(self._response)

    fatal: [localhost]: FAILED! => {
        "changed": false,
        "failed_deployment_operations": [],
        "invocation": {
            "module_args": {
                "ad_user": null,
                "append_tags": true,
                "cli_default_profile": null,
                "client_id": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "cloud_environment": null,
                "deployment_mode": "incremental",
                "deployment_name": "ansible-arm",
                "location": "uk west",
                "parameters": {
                    "tentacleApiKey": {
                        "value": "XXX-ABC-DDE-DDJD-GGGJ"
                    },
                    "tentacleCommunicationMode": {
                        "value": "Listen"
                    },
                    "tentacleEnvironments": {
                        "value": "Test"
                    },
                    "tentacleOctopusServerUrl": {
                        "value": "https://octopus.example.com"
                    },
                    "tentaclePort": {
                        "value": 10933
                    },
                    "tentacleRoles": {
                        "value": "web"
                    },
                    "vmAdminPassword": {
                        "value": "mYpAss"
                    },
                    "vmAdminUserName": {
                        "value": "adminUser"
                    },
                    "vmDnsName": {
                        "value": "WinVM01"
                    }
                },
                "parameters_link": null,
                "password": null,
                "profile": null,
                "resource_group_name": "AnsibleRG",
                "secret": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "state": "present",
                "subscription_id": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "tags": null,
                "template": null,
                "template_link": "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/octopus-deploy-tentacle-windows/azuredeploy.json",
                "tenant": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "wait_for_deployment_completion": true,
                "wait_for_deployment_polling_period": 10
            }
        },
        "msg": "Deployment failed with status code: 400 and message: The template deployment 'ansible-arm' is not valid according to the validation procedure. The tracking id is '1bf65caf-3b8c-4521-8370-65bae816404b'. See inner errors for details. Please see https://aka.ms/arm-deploy for usage details."
    }

以下是我在 Azure 门户活动日志中看到的内容

{
    "authorization": {
        "action": "Microsoft.Resources/deployments/write",
        "scope": "/subscriptions/xxx-xxx-xxx-xxx/resourcegroups/AnsibleRG/providers/Microsoft.Resources/deployments/ansible-arm"
    },
    "caller": "2c02c92d-c9b8-4fc2-8140-40f8ba2052a5",
    "channels": "Operation",
    "claims": {
        "aud": "https://management.core.windows.net/",
        "iss": "https://sts.windows.net/78e60c0f-344b-405f-8c9a-63fe13a30962/",
        "iat": "1518116812",
        "nbf": "1518116812",
        "exp": "1518120712",
        "aio": "Y2NgYDjveebWbh3lRJuJone1i7fPAwA=",
        "appid": "004bc69c-cae7-45a3-8bed-9b37bce64746",
        "appidacr": "1",
        "http://schemas.microsoft.com/identity/claims/identityprovider": "https://sts.windows.net/78e60c0f-344b-405f-8c9a-63fe13a30962/",
        "http://schemas.microsoft.com/identity/claims/objectidentifier": "2c02c92d-c9b8-4fc2-8140-40f8ba2052a5",
        "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "2c02c92d-c9b8-4fc2-8140-40f8ba2052a5",
        "http://schemas.microsoft.com/identity/claims/tenantid": "78e60c0f-344b-405f-8c9a-63fe13a30962",
        "uti": "xhHR-2Xepke_G1gchNgPAA",
        "ver": "1.0"
    },
    "correlationId": "1bf65caf-3b8c-4521-8370-65bae816404b",
    "description": "",
    "eventDataId": "9c32a95d-ed19-4b1f-9826-d68e45742629",
    "eventName": {
        "value": "EndRequest",
        "localizedValue": "End request"
    },
    "category": {
        "value": "Administrative",
        "localizedValue": "Administrative"
    },
    "eventTimestamp": "2018-02-08T19:11:54.0105833Z",
    "id": "/subscriptions/xxx-xxx-xxx-xxx/resourcegroups/AnsibleRG/providers/Microsoft.Resources/deployments/ansible-arm/events/9c32a95d-ed19-4b1f-9826-d68e45742629/ticks/636537139140105833",
    "level": "Error",
    "operationId": "1bf65caf-3b8c-4521-8370-65bae816404b",
    "operationName": {
        "value": "Microsoft.Resources/deployments/write",
        "localizedValue": "Microsoft.Resources/deployments/write"
    },
    "resourceGroupName": "AnsibleRG",
    "resourceProviderName": {
        "value": "Microsoft.Resources",
        "localizedValue": "Microsoft Resources"
    },
    "resourceType": {
        "value": "Microsoft.Resources/deployments",
        "localizedValue": "Microsoft.Resources/deployments"
    },
    "resourceId": "/subscriptions/xxx-xxx-xxx-xxx/resourcegroups/AnsibleRG/providers/Microsoft.Resources/deployments/ansible-arm",
    "status": {
        "value": "Failed",
        "localizedValue": "Failed"
    },
    "subStatus": {
        "value": "BadRequest",
        "localizedValue": "Bad Request (HTTP Status Code: 400)"
    },
    "submissionTimestamp": "2018-02-08T19:12:10.4497444Z",
    "subscriptionId": "xxx-xxx-xxx-xxx",
    "properties": {
        "statusCode": "BadRequest",
        "serviceRequestId": null,
        "statusMessage": "{\"error\":{\"code\":\"InvalidTemplateDeployment\",\"message\":\"The template deployment 'ansible-arm' is not valid according to the validation procedure. The tracking id is '1bf65caf-3b8c-4521-8370-65bae816404b'. See inner errors for details. Please see https://aka.ms/arm-deploy for usage details.\",\"details\":[{\"code\":\"InvalidDomainNameLabel\",\"message\":\"The domain name label WinVM01 is invalid. It must conform to the following regular expression: ^[a-z][a-z0-9-]{1,61}[a-z0-9]$.\",\"details\":[]}]}}"
    },
    "relatedEvents": []
}

谢谢, 射频

【问题讨论】:

  • 我不记得它是否有帮助,您可以使用 -vvvv 开始剧本并将真正的错误粘贴到问题中吗?如果它不使用:get-azurermlog -correlationid c73feca6-ae2d-4c10-83a0-16be06819f5a 来获取错误。或者转到门户,打开“监控”刀片、活动并搜索部署验证错误并在 json 输出中查找真正原因并将其粘贴到此处
  • 刚刚用错误详情更新了问题
  • 你可能应该删除所有额外的数据,只留下'properties'节点

标签: azure ansible


【解决方案1】:

错误是:

The domain name label WinVM01 is invalid. It must conform to the following regular expression: ^[a-z][a-z0-9-]{1,61}[a-z0-9]$

基本上没有大写字母

【讨论】:

  • 感谢您的帮助。但是现在当我运行它创建一个新的虚拟机的剧本时,我想将扩展附加到现有的虚拟机。我该怎么做?
  • 我会修改这个模板,否则很难让它工作,如果你想将扩展添加到虚拟机,你真的只需要模板中的 1 个资源(扩展)
  • 但通常在这种情况下,您需要 vmname 变量来匹配您的虚拟机名称
  • 似乎使用 azure-quickstart-templates 进行 Octopus Deploy 并不是在启动新机器时向现有 VM 添加扩展的方法。我无法找到将 Azure 扩展添加到现有机器的方法。我主要对将反恶意软件扩展添加到正在运行的机器感兴趣。如果我为此记录一个单独的问题,也许会更好。
猜你喜欢
  • 1970-01-01
  • 2020-11-11
  • 2018-01-26
  • 1970-01-01
  • 1970-01-01
  • 2018-10-30
  • 2016-04-18
  • 2018-10-12
  • 1970-01-01
相关资源
最近更新 更多