community.libvirt.virt 模块 – 管理 libvirt 支持的虚拟机
注意
此模块是 community.libvirt 集合 (版本 1.3.0) 的一部分。
如果您正在使用 ansible
包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.libvirt
。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求。
要在 playbook 中使用它,请指定:community.libvirt.virt
。
概要
管理 *libvirt* 支持的虚拟机。
要求
执行此模块的主机需要以下要求。
python >= 2.6
libvirt python 绑定
参数
参数 |
注释 |
---|---|
主机启动时启动虚拟机。 选项
|
|
除了状态管理之外,还提供各种非幂等命令。 选项
|
|
传递附加参数。 目前仅在命令 选项
|
|
强制执行操作。 目前仅在命令 选项
|
|
对于每个 mutate_flag,我们将以某种方式修改给定的 XML ADD_UUID 将在缺少的情况下将现有域的 UUID 添加到 xml ADD_MAC_ADDRESSES 将查找现有域中具有匹配别名的接口并复制 MAC 地址。匹配的接口不需要是相同类型或源网络。 ADD_MAC_ADDRESSES_FUZZY 将尝试将传入的接口与共享相同类型和源网络/设备的现有域的接口匹配。它可能并不总是产生预期的结果,特别是如果域有多个接口连接到同一个主机设备,而只有其中一些设备具有 选项
默认值: |
|
正在管理的客户机虚拟机的名称。请注意,虚拟机必须使用 xml 预先定义。 除非 *command* 为 |
|
请注意,对于 选项
|
|
Libvirt 连接 uri。 默认值: |
|
与 define 命令一起使用的 XML 文档。 必须使用 |
示例
# a playbook task line:
- name: Start a VM
community.libvirt.virt:
name: alpha
state: running
# /usr/bin/ansible invocations
# ansible host -m virt -a "name=alpha command=status"
# ansible host -m virt -a "name=alpha command=get_xml"
# ansible host -m virt -a "name=alpha command=create uri=lxc:///"
# defining and launching an LXC guest
- name: Define a VM
community.libvirt.virt:
command: define
xml: "{{ lookup('template', 'container-template.xml.j2') }}"
uri: 'lxc:///'
- name: start vm
community.libvirt.virt:
name: foo
state: running
uri: 'lxc:///'
# setting autostart on a qemu VM (default uri)
- name: Set autostart for a VM
community.libvirt.virt:
name: foo
autostart: true
# Defining a VM and making is autostart with host. VM will be off after this task
- name: Define vm from xml and set autostart
community.libvirt.virt:
command: define
xml: "{{ lookup('template', 'vm_template.xml.j2') }}"
autostart: true
# Undefine VM only, if it has no existing nvram or other metadata
- name: Undefine qemu VM
community.libvirt.virt:
name: foo
# Undefine VM and force remove all of its related metadata (nvram, snapshots, etc.)
- name: "Undefine qemu VM with force"
community.libvirt.virt:
name: foo
force: true
# Undefine VM and remove all of its specified metadata specified
# Result would the same as with force=true
- name: Undefine qemu VM with list of flags
community.libvirt.virt:
name: foo
flags: managed_save, snapshots_metadata, nvram, checkpoints_metadata
# Undefine VM, but keep its nvram
- name: Undefine qemu VM and keep its nvram
community.libvirt.virt:
name: foo
flags: keep_nvram
# Listing VMs
- name: List all VMs
community.libvirt.virt:
command: list_vms
register: all_vms
- name: List only running VMs
community.libvirt.virt:
command: list_vms
state: running
register: running_vms
返回值
常见的返回值已在此处记录,以下是此模块特有的字段
键 |
描述 |
---|---|
远程系统上定义的虚拟机列表。 返回值: 成功 示例: |
|
虚拟机的状态,包括运行中、崩溃、暂停和关机。 返回值: 成功 示例: |