加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ansible:virt模块XML错误

发布时间:2020-12-16 22:52:43 所属栏目:百科 来源:网络整理
导读:我正在尝试使用virt模块和 XML文件定义VM.这个任务: - name: Define VM using the XML file virt: command=define name={{ new_vm_name }} xml={{ vm_images_path }}/{{ new_vm_xml }} remote_user: root delegate_to: "{{ hyperv }}" 失败并出现此错误: f
我正在尝试使用virt模块和 XML文件定义VM.这个任务:

- name: Define VM using the XML file
   virt: command=define
         name={{ new_vm_name }}
         xml={{ vm_images_path }}/{{ new_vm_xml }}
   remote_user: root
   delegate_to: "{{ hyperv }}"

失败并出现此错误:

failed: [vm-002 -> nat] => {"failed": true}
msg: (domain_definition):1: Start tag expected,'<' not found
/var/lib/libvirt/images//vm-002-ver1.1.0-00042.xml

虽然这有效:

- name: Define VM using the XML file
   command: virsh define {{ vm_images_path }}/{{ new_vm_xml }}
   remote_user: root
   delegate_to: "{{ hyperv }}"

在这两种情况下,XML文件是相同的,任何想法为什么第一个失败?我总是喜欢使用模块而不是自定义命令,所以我真的想让第一个工作.

解决方法

virt模块的xml参数采用XML字符串,而不是文件名.

你可以达到你想要的效果:

- name: Define VM using the XML file
   virt: command=define
         name={{ new_vm_name }}
         xml={{ lookup('template','./libvirt_create_template.j2') }}
   remote_user: root
   delegate_to: "{{ hyperv }}"

您在查找中引用的文件位于Ansible控制服务器上(即您运行Playbooks的位置).

通过使用模板查找,您可以将VM特定设置替换为要安装的VM的清单中的值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读