无法使用ansible从捕获的蔚蓝图像中创建VM

问题描述 投票:0回答:1

我正在尝试使用Ansible创建Azure Windows映像,并将其作为基础设施自动化项目的一部分。在执行剧本时,所有事情都会经过:

enter image description here

我的剧本看起来像这样:

enter image description here

有两个角色Generalize-windows和azure-imageCreator。

generalize-windows.yml像这样从内部概括窗口:

enter image description here

当azure-imageCreator取消分配,概括和捕获图像时:

- name: deallocate vm
  azure_rm_virtualmachine:
  resource_group: "{{ resource_group_vm }}"
  name: "{{ vm_name }}{{random_suffix}}-image"
  allocated: no


- name: Call REST API - VirtualMachines_Generalize
      azure_rm_resource:
        api_version: '2017-12-01'
        method: POST
        resource_group: "{{ resource_group_vm }}"
        provider: compute
        resource_type: virtualmachines
        resource_name: "{{ vm_name }}{{random_suffix}}"
        subresource:
            - type: generalize  

    - name: Create an image from a virtual machine
      azure_rm_image:
        resource_group: "{{ resource_group_vm }}"
        os_type: Windows
        name: "{{ vm_name }}{{random_suffix}}-image"
        source: "{{ vm_name }}{{random_suffix}}"

现在,当我从ansible创建的映像中创建虚拟机时,出现以下错误:

"details": [
    {
      "code": "Conflict",
      "message": "{\r\n  \"status\": \"Failed\",\r\n  \"error\": {\r\n    \"code\": \"ResourceDeploymentFailure\",\r\n    \"message\": \"The resource operation completed with terminal provisioning state 'Failed'.\",\r\n    \"details\": [\r\n      {\r\n        \"code\": \"OSProvisioningClientError\",\r\n        \"message\": \"OS Provisioning for VM 'p' did not finish in the allotted time. However, the VM guest agent was detected running. This suggests the guest OS has not been properly prepared to be used as a VM image (with CreateOption=FromImage). To resolve this issue, either use the VHD as is with CreateOption=Attach or prepare it properly for use as an image:\\r\\n * Instructions for Windows: https://azure.microsoft.com/documentation/articles/virtual-machines-windows-upload-image/ \\r\\n * Instructions for Linux: https://azure.microsoft.com/documentation/articles/virtual-machines-linux-capture-image/ \"\r\n      }\r\n    ]\r\n  }\r\n}"
    }
  ]
}

有人可以告诉我我哪里错了吗?

azure ansible azure-virtual-machine
1个回答
0
投票

我相当确定您首先需要sysprep VM。 generalize API调用不会对它进行sysprep处理,只会将其标记为sysprepped。

https://docs.microsoft.com/en-us/azure/virtual-machines/windows/capture-image-resource#generalize-the-windows-vm-using-sysprep

© www.soinside.com 2019 - 2024. All rights reserved.