我为它编写了 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 模块进行磁盘更新。
关于azure - 使用 ansible playbook 更新 azure windows vm 中的磁盘存储类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68754567/