community.libvirt.virt_pool 模块 – 管理 libvirt 存储池
注意
此模块是 community.libvirt 集合(版本 1.3.0)的一部分。
如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.libvirt。您需要更多要求才能使用此模块,请参阅 要求 了解详细信息。
要在 Playbook 中使用它,请指定:community.libvirt.virt_pool。
概要
- 管理 libvirt 存储池。 
要求
执行此模块的主机需要满足以下要求。
- libvirt python 绑定 
- python >= 2.6 
- python-lxml 
参数
| 参数 | 注释 | 
|---|---|
| 指定给定的存储池是否应在系统启动时自动启动。 选择 
 | |
| 除了状态管理之外,还有各种非幂等命令可用。请参阅示例。 选择 
 | |
| 将其他参数传递给 'build' 或 'delete' 命令。 选择 
 | |
| 正在管理的存储池的名称。请注意,池必须事先使用 XML 定义。 | |
| 指定您希望存储池处于哪种状态。如果为 “active”,则将启动池。如果为 “present”,则确保池存在但不更改其状态;如果它丢失,则需要指定 xml 参数。如果为 “inactive”,则将停止池。如果为 “undefined” 或 “absent”,则将从 libvirt 配置中删除池。如果为 “deleted”,则将删除池内容,然后取消定义池。 选择 
 | |
| Libvirt 连接 URI。 默认:  | |
| 用于定义命令的 XML 文档。 必须是使用  | 
示例
- name: Define a new storage pool
  community.libvirt.virt_pool:
    command: define
    name: vms
    xml: '{{ lookup("template", "pool/dir.xml.j2") }}'
- name: Build a storage pool if it does not exist
  community.libvirt.virt_pool:
    command: build
    name: vms
- name: Start a storage pool
  community.libvirt.virt_pool:
    command: create
    name: vms
- name: List available pools
  community.libvirt.virt_pool:
    command: list_pools
- name: Get XML data of a specified pool
  community.libvirt.virt_pool:
    command: get_xml
    name: vms
- name: Stop a storage pool
  community.libvirt.virt_pool:
    command: destroy
    name: vms
- name: Delete a storage pool (destroys contents)
  community.libvirt.virt_pool:
    command: delete
    name: vms
- name: Undefine a storage pool
  community.libvirt.virt_pool:
    command: undefine
    name: vms
# Gather facts about storage pools
# Facts will be available as 'ansible_libvirt_pools'
- name: Gather facts about storage pools
  community.libvirt.virt_pool:
    command: facts
- name: Gather information about pools managed by 'libvirt' remotely using uri
  community.libvirt.virt_pool:
    command: info
    uri: '{{ item }}'
  with_items: '{{ libvirt_uris }}'
  register: storage_pools
- name: Ensure that a pool is active (needs to be defined and built first)
  community.libvirt.virt_pool:
    state: active
    name: vms
- name: Ensure that a pool is inactive
  community.libvirt.virt_pool:
    state: inactive
    name: vms
- name: Ensure that a given pool will be started at boot
  community.libvirt.virt_pool:
    autostart: true
    name: vms
- name: Disable autostart for a given pool
  community.libvirt.virt_pool:
    autostart: false
    name: vms
