ovirt.ovirt_collection.ovirt_disk (1.0.2) — module

Module to manage Virtual Machine and floating disks in oVirt/RHV

| "added in version" 1.0.0 of ovirt.ovirt_collection"

Authors: Ondra Machacek (@machacekondra), Martin Necas (@mnecas)

preview | supported by community

Install collection

Install with ansible-galaxy collection install ovirt.ovirt_collection:==1.0.2


Add to requirements.yml

  collections:
    - name: ovirt.ovirt_collection
      version: 1.0.2

Description

Module to manage Virtual Machine and floating disks in oVirt/RHV.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Examples don't contain auth parameter for simplicity,
# look at ovirt_auth module to see how to reuse authentication:

# Create and attach new disk to VM
- ovirt_disk:
    name: myvm_disk
    vm_name: rhel7
    size: 10GiB
    format: cow
    interface: virtio
    storage_domain: data
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Attach logical unit to VM rhel7
- ovirt_disk:
    vm_name: rhel7
    logical_unit:
      target: iqn.2016-08-09.brq.str-01:omachace
      id: 1IET_000d0001
      address: 10.34.63.204
    interface: virtio
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Detach disk from VM
- ovirt_disk:
    state: detached
    name: myvm_disk
    vm_name: rhel7
    size: 10GiB
    format: cow
    interface: virtio
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Change Disk Name
- ovirt_disk:
    id: 00000000-0000-0000-0000-000000000000
    storage_domain: data
    name: "new_disk_name"
    vm_name: rhel7
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Upload local image to disk and attach it to vm:
# Since Ansible 2.3
- ovirt_disk:
    name: mydisk
    vm_name: myvm
    interface: virtio
    size: 10GiB
    format: cow
    image_path: /path/to/mydisk.qcow2
    storage_domain: data
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Download disk to local file system:
# Since Ansible 2.3
- ovirt_disk:
    id: 7de90f31-222c-436c-a1ca-7e655bd5b60c
    download_image_path: /home/user/mydisk.qcow2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Export disk as image to Glance domain
# Since Ansible 2.4
- ovirt_disk:
    id: 7de90f31-222c-436c-a1ca-7e655bd5b60c
    image_provider: myglance
    state: exported
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Defining a specific quota while creating a disk image:
# Since Ansible 2.5
- ovirt_quotas_facts:
    data_center: Default
    name: myquota
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- ovirt_disk:
    name: mydisk
    size: 10GiB
    storage_domain: data
    description: somedescriptionhere
    quota_id: "{{ ovirt_quotas[0]['id'] }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Upload an ISO image
# Since Ansible 2.8
-  ovirt_disk:
     name: myiso
     upload_image_path: /path/to/iso/image
     storage_domain: data
     size: 4 GiB
     wait: true
     bootable: true
     format: raw
     content_type: iso
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Add fiber chanel disk
- name: Create disk
  ovirt_disk:
    name: fcp_disk
    host: my_host
    logical_unit:
        id: 3600a09803830447a4f244c4657597777
        storage_type: fcp

Inputs

    
id:
    description:
    - ID of the disk to manage. Either C(id) or C(name) is required.

auth:
    description:
    - 'Dictionary with values needed to create HTTP/HTTPS connection to oVirt:'
    required: true
    suboptions:
      ca_file:
        description:
        - A PEM file containing the trusted CA certificates.
        - The certificate presented by the server will be verified using these CA certificates.
        - If C(ca_file) parameter is not set, system wide CA certificate store is used.
        - Default value is set by C(OVIRT_CAFILE) environment variable.
        type: str
      headers:
        description:
        - Dictionary of HTTP headers to be added to each API call.
        type: dict
      hostname:
        description:
        - A string containing the hostname of the server, usually something like `I(server.example.com)`.
        - Default value is set by C(OVIRT_HOSTNAME) environment variable.
        - Either C(url) or C(hostname) is required.
        type: str
      insecure:
        description:
        - A boolean flag that indicates if the server TLS certificate and host name should
          be checked.
        type: bool
      kerberos:
        description:
        - A boolean flag indicating if Kerberos authentication should be used instead
          of the default basic authentication.
        type: bool
      password:
        description:
        - The password of the user.
        - Default value is set by C(OVIRT_PASSWORD) environment variable.
        required: true
        type: str
      token:
        description:
        - Token to be used instead of login with username/password.
        - Default value is set by C(OVIRT_TOKEN) environment variable.
        type: str
      url:
        description:
        - A string containing the API URL of the server, usually something like `I(https://server.example.com/ovirt-engine/api)`.
        - Default value is set by C(OVIRT_URL) environment variable.
        - Either C(url) or C(hostname) is required.
        type: str
      username:
        description:
        - The name of the user, something like I(admin@internal).
        - Default value is set by C(OVIRT_USERNAME) environment variable.
        required: true
        type: str
    type: dict

host:
    description:
    - When the hypervisor name is specified the newly created disk or an existing disk
      will refresh its information about the underlying storage( Disk size, Serial, Product
      ID, Vendor ID ...) The specified host will be used for gathering the storage related
      information. This option is only valid for passthrough disks. This option requires
      at least the logical_unit.id to be specified

name:
    aliases:
    - alias
    description:
    - Name of the disk to manage. Either C(id) or C(name)/C(alias) is required.

size:
    description:
    - Size of the disk. Size should be specified using IEC standard units. For example
      10GiB, 1024MiB, etc.
    - Size can be only increased, not decreased.

wait:
    default: true
    description:
    - C(yes) if the module should wait for the entity to get into desired state.
    type: bool

force:
    description:
    - Please take a look at C(image_path) documentation to see the correct usage of this
      parameter.
    type: bool

state:
    choices:
    - present
    - absent
    - attached
    - detached
    - exported
    - imported
    default: present
    description:
    - Should the Virtual Machine disk be present/absent/attached/detached/exported/imported.

vm_id:
    description:
    - ID of the Virtual Machine to manage. Either C(vm_id) or C(vm_name) is required if
      C(state) is I(attached) or I(detached).

format:
    choices:
    - raw
    - cow
    description:
    - Specify format of the disk.
    - Note that this option isn't idempotent as it's not currently possible to change
      format of the disk via API.

sparse:
    description:
    - I(True) if the disk should be sparse (also known as I(thin provision)). If the parameter
      is omitted, cow disks will be created as sparse and raw disks as I(preallocated)
    - Note that this option isn't idempotent as it's not currently possible to change
      sparseness of the disk via API.
    required: false
    type: bool

profile:
    description:
    - Disk profile name to be attached to disk. By default profile is chosen by oVirt/RHV
      engine.

timeout:
    default: 180
    description:
    - The amount of time in seconds the module should wait for the instance to get into
      desired state.
    type: int

vm_name:
    description:
    - Name of the Virtual Machine to manage. Either C(vm_id) or C(vm_name) is required
      if C(state) is I(attached) or I(detached).

activate:
    description:
    - I(True) if the disk should be activated.
    - When creating disk of virtual machine it is set to I(True).
    type: bool

bootable:
    default: 'no'
    description:
    - I(True) if the disk should be bootable. By default when disk is created it isn't
      bootable.
    type: bool

quota_id:
    description:
    - Disk quota ID to be used for disk. By default quota is chosen by oVirt/RHV engine.

sparsify:
    description:
    - I(True) if the disk should be sparsified.
    - Sparsification frees space in the disk image that is not used by its filesystem.
      As a result, the image will occupy less space on the storage.
    - Note that this parameter isn't idempotent, as it's not possible to check if the
      disk should be or should not be sparsified.
    type: bool

interface:
    choices:
    - virtio
    - ide
    - virtio_scsi
    description:
    - Driver of the storage interface.
    - It's required parameter when creating the new disk.

shareable:
    description:
    - I(True) if the disk should be shareable. By default when disk is created it isn't
      shareable.
    type: bool

description:
    description:
    - Description of the disk image to manage.

content_type:
    choices:
    - data
    - iso
    - hosted_engine
    - hosted_engine_sanlock
    - hosted_engine_metadata
    - hosted_engine_configuration
    default: data
    description:
    - Specify if the disk is a data disk or ISO image or a one of a the Hosted Engine
      disk types
    - The Hosted Engine disk content types are available with Engine 4.3+ and Ansible
      2.8

fetch_nested:
    description:
    - If I(True) the module will fetch additional data from the API.
    - It will fetch IDs of the VMs disks, snapshots, etc. User can configure to fetch
      other attributes of the nested entities by specifying C(nested_attributes).
    type: bool

logical_unit:
    description:
    - 'Dictionary which describes LUN to be directly attached to VM:'
    suboptions:
      address:
        description:
        - Address of the storage server. Used by iSCSI.
      lun_id:
        description:
        - LUN id.
      password:
        description:
        - CHAP Password of the user to be used to access storage server. Used by iSCSI.
      port:
        description:
        - Port of the storage server. Used by iSCSI.
      storage_type:
        description:
        - Storage type either I(fcp) or I(iscsi).
      target:
        description:
        - iSCSI target.
      username:
        description:
        - CHAP Username to be used to access storage server. Used by iSCSI.

poll_interval:
    default: 3
    description:
    - Number of the seconds the module waits until another poll request on entity status
      is sent.
    type: int

image_provider:
    description:
    - When C(state) is I(exported) disk is exported to given Glance image provider.
    - When C(state) is I(imported) disk is imported from given Glance image provider.
    - C(**IMPORTANT**)
    - There is no reliable way to achieve idempotency, so every time you specify this
      parameter the disk is exported, so please handle your playbook accordingly to not
      export the disk all the time. This option is valid only for template disks.

storage_domain:
    description:
    - Storage domain name where disk should be created.

storage_domains:
    description:
    - Storage domain names where disk should be copied.
    - C(**IMPORTANT**)
    - There is no reliable way to achieve idempotency, so every time you specify this
      parameter the disks are copied, so please handle your playbook accordingly to not
      copy the disks all the time. This is valid only for VM and floating disks, template
      disks works as expected.

nested_attributes:
    description:
    - Specifies list of the attributes which should be fetched from the API.
    - This parameter apply only when C(fetch_nested) is I(true).
    type: list

upload_image_path:
    description:
    - Path to disk image, which should be uploaded.
    - Note that currently we support only compatibility version 0.10 of the qcow disk.
    - Note that you must have an valid oVirt/RHV engine CA in your system trust store
      or you must provide it in C(ca_file) parameter.
    - Note that there is no reliable way to achieve idempotency, so if you want to upload
      the disk even if the disk with C(id) or C(name) exists, then please use C(force)
      I(true). If you will use C(force) I(false), which is default, then the disk image
      won't be uploaded.

wipe_after_delete:
    description:
    - If the disk's Wipe After Delete is enabled, then the disk is first wiped.
    type: bool

download_image_path:
    description:
    - Path on a file system where disk should be downloaded.
    - Note that you must have an valid oVirt/RHV engine CA in your system trust store
      or you must provide it in C(ca_file) parameter.
    - Note that the disk is not downloaded when the file already exists, but you can forcibly
      download the disk when using C(force) I (true).

openstack_volume_type:
    description:
    - Name of the openstack volume type. This is valid when working with cinder.

Outputs

disk:
  description: 'Dictionary of all the disk attributes. Disk attributes can be found
    on your oVirt/RHV instance at following url: http://ovirt.github.io/ovirt-engine-api-model/master/#types/disk.'
  returned: On success if disk is found and C(vm_id) or C(vm_name) wasn't passed.
  type: dict
disk_attachment:
  description: 'Dictionary of all the disk attachment attributes. Disk attachment
    attributes can be found on your oVirt/RHV instance at following url: http://ovirt.github.io/ovirt-engine-api-model/master/#types/disk_attachment.'
  returned: On success if disk is found and C(vm_id) or C(vm_name) was passed and
    VM was found.
  type: dict
id:
  description: ID of the managed disk
  returned: On success if disk is found.
  sample: 7de90f31-222c-436c-a1ca-7e655bd5b60c
  type: str