azure - 使用 ansible playbook 更新 azure windows vm 中的磁盘存储类型

标签 azure jenkins ansible virtual-machine

我为它编写了 4 个任务,第一个用于关闭虚拟机电源,第二个用于验证虚拟机是否已停止,第三个用于更新然后打开虚拟机电源。但问题是,即使机器停止,ansible 也会给出错误“不允许操作”。您可以看到下面的错误。由于我是 ansible 的新手,请建议我正确的方法。另请说明哪个任务在 localhost 上运行,哪个在 Windows 上运行。

致命:[localhost]:失败! => {"changed": false, "msg": "创建托管磁盘时出错:Azure 错误:OperationNotAllowed\n消息:在附加到运行时无法更改磁盘 <> 的帐户类型、容错域或网络主干虚拟机 <>。"}

- name: Update Disk type
  hosts: localhost
  gather_facts: no
  tasks:
  - name: Power off the VM
    azure_rm_virtualmachine:
      resource_group: "{{resource_group}}"
      name: "{{vm_name}}"
      started: no

  - name: Verify that the machine is stopped
    win_ping:
    #delegate_to: localhost
    failed_when: false
    ignore_unreachable: true
    register: ping_result

  - debug: var=ping_result

  - name: Update the disk type
    azure_rm_manageddisk:
      name: "{{disk_name}}"
      resource_group: "{{resource_group}}"
      storage_account_type: "{{type}}"
      disk_size_gb: "{{size}}"
 
  - name: Power on the VM
    azure_rm_virtualmachine:
      resource_group: "{{resource_group}}"
      name: "{{vm_name}}"

最佳答案

问题已通过更改解决

name: Power off the VM
    azure_rm_virtualmachine:
      resource_group: "{{resource_group}}"
      name: "{{vm_name}}"
      started: no

name: Power off the VM
    azure_rm_virtualmachine:
      resource_group: "{{resource_group}}"
      name: "{{vm_name}}"
      allocated: no

此外,根据 Richa 的更新,我们需要使用 az CLI 来更新磁盘,因为在 Ansible 的 Github 存储库中提到,由于某些服务器限制,无法通过 ansible 模块进行磁盘更新。

引用:az disk | Microsoft Docs

关于azure - 使用 ansible playbook 更新 azure windows vm 中的磁盘存储类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68754567/

相关文章:

java - 如何自动创建发行说明/更新日志?

ansible - 使用 with_nested 和 Ansible

variables - Ansible:在循环中生成变量

asp.net - facebook api 错误代码 : 191 Asp. 使用开发环境 localhost 和 ACS 的 Net MVC 3

python - 自动在 Azure ML Studio Designer 中注册自定义模型并在设计器内部署

c# - 不处理 Azure ASP.NET REST Web 服务调用

authentication - Jenkins 使用 OpenID 身份验证将访问权限限制为仅 Google Apps 域用户

database - 从 TFS 迁移到 VSTS - 数据库警告 : Ignore or Abort

android - 任何有助于使用 Jenkins 构建 Android 应用程序

java - 如何使用 Ansible 安装 Oracle Java 8