community.general.xenserver_guest (8.5.0) — module

Manages virtual machines running on Citrix Hypervisor/XenServer host or pool

Authors: Bojan Vitnik (@bvitnik) <bvitnik@mainstream.rs>

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

This module can be used to create new virtual machines from templates or other virtual machines, modify various virtual machine components like network and disk, rename a virtual machine and remove a virtual machine with associated components.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a VM from a template
  community.general.xenserver_guest:
    hostname: "{{ xenserver_hostname }}"
    username: "{{ xenserver_username }}"
    password: "{{ xenserver_password }}"
    folder: /testvms
    name: testvm_2
    state: poweredon
    template: CentOS 7
    disks:
    - size_gb: 10
      sr: my_sr
    hardware:
      num_cpus: 6
      num_cpu_cores_per_socket: 3
      memory_mb: 512
    cdrom:
      type: iso
      iso_name: guest-tools.iso
    networks:
    - name: VM Network
      mac: aa:bb:dd:aa:00:14
    wait_for_ip_address: true
  delegate_to: localhost
  register: deploy
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create a VM template
  community.general.xenserver_guest:
    hostname: "{{ xenserver_hostname }}"
    username: "{{ xenserver_username }}"
    password: "{{ xenserver_password }}"
    folder: /testvms
    name: testvm_6
    is_template: true
    disk:
    - size_gb: 10
      sr: my_sr
    hardware:
      memory_mb: 512
      num_cpus: 1
  delegate_to: localhost
  register: deploy
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Rename a VM (requires the VM's UUID)
  community.general.xenserver_guest:
    hostname: "{{ xenserver_hostname }}"
    username: "{{ xenserver_username }}"
    password: "{{ xenserver_password }}"
    uuid: 421e4592-c069-924d-ce20-7e7533fab926
    name: new_name
    state: present
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove a VM by UUID
  community.general.xenserver_guest:
    hostname: "{{ xenserver_hostname }}"
    username: "{{ xenserver_username }}"
    password: "{{ xenserver_password }}"
    uuid: 421e4592-c069-924d-ce20-7e7533fab926
    state: absent
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Modify custom params (boot order)
  community.general.xenserver_guest:
    hostname: "{{ xenserver_hostname }}"
    username: "{{ xenserver_username }}"
    password: "{{ xenserver_password }}"
    name: testvm_8
    state: present
    custom_params:
    - key: HVM_boot_params
      value: { "order": "ndc" }
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Customize network parameters
  community.general.xenserver_guest:
    hostname: "{{ xenserver_hostname }}"
    username: "{{ xenserver_username }}"
    password: "{{ xenserver_password }}"
    name: testvm_10
    networks:
    - name: VM Network
      ip: 192.168.1.100/24
      gateway: 192.168.1.1
    - type: dhcp
  delegate_to: localhost

Inputs

    
name:
    aliases:
    - name_label
    description:
    - Name of the VM to work with.
    - VMs running on XenServer do not necessarily have unique names. The module will fail
      if multiple VMs with same name are found.
    - In case of multiple VMs with same name, use O(uuid) to uniquely specify VM to manage.
    - This parameter is case sensitive.
    type: str

uuid:
    description:
    - UUID of the VM to manage if known. This is XenServer's unique identifier.
    - It is required if name is not unique.
    - Please note that a supplied UUID will be ignored on VM creation, as XenServer creates
      the UUID internally.
    type: str

cdrom:
    description:
    - A CD-ROM configuration for the VM.
    - All parameters are case sensitive.
    suboptions:
      iso_name:
        description:
        - The file name of an ISO image from one of the XenServer ISO Libraries (implies
          O(cdrom.type=iso)).
        - Required if O(cdrom.type) is set to V(iso).
        type: str
      type:
        choices:
        - none
        - iso
        description:
        - The type of CD-ROM. With V(none) the CD-ROM device will be present but empty.
        type: str
    type: dict

disks:
    aliases:
    - disk
    description:
    - A list of disks to add to VM.
    - All parameters are case sensitive.
    - Removing or detaching existing disks of VM is not supported.
    - New disks are required to have either a O(disks[].size) or one of O(ignore:disks[].size_[tb,gb,mb,kb,b])
      parameters specified.
    - VM needs to be shut down to reconfigure disk size.
    elements: dict
    suboptions:
      name:
        aliases:
        - name_label
        description:
        - Disk name.
        type: str
      name_desc:
        description:
        - Disk description.
        type: str
      size:
        description:
        - 'Disk size with unit. Unit must be: V(b), V(kb), V(mb), V(gb), V(tb). VM needs
          to be shut down to reconfigure this parameter.'
        - If no unit is specified, size is assumed to be in bytes.
        type: str
      size_b:
        description:
        - Disk size in bytes.
        type: str
      size_gb:
        description:
        - Disk size in gigabytes.
        type: str
      size_kb:
        description:
        - Disk size in kilobytes.
        type: str
      size_mb:
        description:
        - Disk size in megabytes.
        type: str
      size_tb:
        description:
        - Disk size in terabytes.
        type: str
      sr:
        description:
        - Storage Repository to create disk on. If not specified, will use default SR.
          Cannot be used for moving disk to other SR.
        type: str
      sr_uuid:
        description:
        - UUID of a SR to create disk on. Use if SR name is not unique.
        type: str
    type: list

force:
    default: false
    description:
    - Ignore warnings and complete the actions.
    - This parameter is useful for removing VM in running state or reconfiguring VM params
      that require VM to be shut down.
    type: bool

state:
    choices:
    - present
    - absent
    - poweredon
    default: present
    description:
    - Specify the state VM should be in.
    - If O(state) is set to V(present) and VM exists, ensure the VM configuration conforms
      to given parameters.
    - If O(state) is set to V(present) and VM does not exist, then VM is deployed with
      given parameters.
    - If O(state) is set to V(absent) and VM exists, then VM is removed with its associated
      components.
    - If O(state) is set to V(poweredon) and VM does not exist, then VM is deployed with
      given parameters and powered on automatically.
    type: str

folder:
    description:
    - Destination folder for VM.
    - This parameter is case sensitive.
    - 'Example:'
    - '  folder: /folder1/folder2'
    type: str

hardware:
    description:
    - Manage VM's hardware parameters. VM needs to be shut down to reconfigure these parameters.
    suboptions:
      memory_mb:
        description:
        - Amount of memory in MB.
        type: int
      num_cpu_cores_per_socket:
        description:
        - Number of Cores Per Socket. O(hardware.num_cpus) has to be a multiple of O(hardware.num_cpu_cores_per_socket).
        type: int
      num_cpus:
        description:
        - Number of CPUs.
        type: int
    type: dict

hostname:
    aliases:
    - host
    - pool
    default: localhost
    description:
    - The hostname or IP address of the XenServer host or XenServer pool master.
    - If the value is not specified in the task, the value of environment variable E(XENSERVER_HOST)
      will be used instead.
    type: str

networks:
    aliases:
    - network
    description:
    - A list of networks (in the order of the NICs).
    - All parameters are case sensitive.
    - Name is required for new NICs. Other parameters are optional in all cases.
    elements: dict
    suboptions:
      gateway:
        description:
        - Static IPv4 gateway.
        type: str
      gateway6:
        description:
        - Static IPv6 gateway.
        type: str
      ip:
        description:
        - Static IPv4 address (implies O(networks[].type=static)). Can include prefix
          in format C(<IPv4 address>/<prefix>) instead of using C(netmask).
        type: str
      ip6:
        description:
        - Static IPv6 address (implies O(networks[].type6=static)) with prefix in format
          C(<IPv6 address>/<prefix>).
        type: str
      mac:
        description:
        - Customize MAC address of the interface.
        type: str
      name:
        aliases:
        - name_label
        description:
        - Name of a XenServer network to attach the network interface to.
        type: str
      netmask:
        description:
        - Static IPv4 netmask required for O(networks[].ip) if prefix is not specified.
        type: str
      type:
        choices:
        - none
        - dhcp
        - static
        description:
        - Type of IPv4 assignment. Value V(none) means whatever is default for OS.
        - On some operating systems it could be DHCP configured (e.g. Windows) or unconfigured
          interface (e.g. Linux).
        type: str
      type6:
        choices:
        - none
        - dhcp
        - static
        description:
        - Type of IPv6 assignment. Value V(none) means whatever is default for OS.
        type: str
    type: list

password:
    aliases:
    - pass
    - pwd
    description:
    - The password to use for connecting to XenServer.
    - If the value is not specified in the task, the value of environment variable E(XENSERVER_PASSWORD)
      will be used instead.
    type: str

template:
    aliases:
    - template_src
    description:
    - Name of a template, an existing VM (must be shut down) or a snapshot that should
      be used to create VM.
    - Templates/VMs/snapshots on XenServer do not necessarily have unique names. The module
      will fail if multiple templates with same name are found.
    - In case of multiple templates/VMs/snapshots with same name, use O(template_uuid)
      to uniquely specify source template.
    - If VM already exists, this setting will be ignored.
    - This parameter is case sensitive.
    type: str

username:
    aliases:
    - admin
    - user
    default: root
    description:
    - The username to use for connecting to XenServer.
    - If the value is not specified in the task, the value of environment variable E(XENSERVER_USER)
      will be used instead.
    type: str

name_desc:
    description:
    - VM description.
    type: str

home_server:
    description:
    - Name of a XenServer host that will be a Home Server for the VM.
    - This parameter is case sensitive.
    type: str

is_template:
    default: false
    description:
    - Convert VM to template.
    type: bool

linked_clone:
    default: false
    description:
    - Whether to create a Linked Clone from the template, existing VM or snapshot. If
      no, will create a full copy.
    - This is equivalent to C(Use storage-level fast disk clone) option in XenCenter.
    type: bool

custom_params:
    description:
    - Define a list of custom VM params to set on VM.
    - Useful for advanced users familiar with managing VM params through xe CLI.
    - A custom value object takes two fields O(custom_params[].key) and O(custom_params[].value)
      (see example below).
    elements: dict
    suboptions:
      key:
        description:
        - VM param name.
        required: true
        type: str
      value:
        description:
        - VM param value.
        required: true
        type: raw
    type: list

template_uuid:
    description:
    - UUID of a template, an existing VM or a snapshot that should be used to create VM.
    - It is required if template name is not unique.
    type: str

validate_certs:
    default: true
    description:
    - Allows connection when SSL certificates are not valid. Set to V(false) when certificates
      are not trusted.
    - If the value is not specified in the task, the value of environment variable E(XENSERVER_VALIDATE_CERTS)
      will be used instead.
    type: bool

wait_for_ip_address:
    default: false
    description:
    - Wait until XenServer detects an IP address for the VM. If O(state) is set to V(absent),
      this parameter is ignored.
    - This requires XenServer Tools to be preinstalled on the VM to work properly.
    type: bool

state_change_timeout:
    default: 0
    description:
    - By default, module will wait indefinitely for VM to acquire an IP address if O(wait_for_ip_address=true).
    - If this parameter is set to positive value, the module will instead wait specified
      number of seconds for the state change.
    - In case of timeout, module will generate an error message.
    type: int

Outputs

changes:
  description: Detected or made changes to VM
  returned: always
  sample:
  - hardware:
    - num_cpus
  - disks_changed:
    - []
    - - size
  - disks_new:
    - name: new-disk
      name_desc: ''
      position: 2
      size_gb: '4'
      vbd_userdevice: '2'
  - cdrom:
    - type
    - iso_name
  - networks_changed:
    - - mac
  - networks_new:
    - name: Pool-wide network associated with eth2
      position: 1
      vif_device: '1'
  - need_poweredoff
  type: list
instance:
  description: Metadata about the VM
  returned: always
  sample:
    cdrom:
      type: none
    customization_agent: native
    disks:
    - name: testvm_11-0
      name_desc: ''
      os_device: xvda
      size: 42949672960
      sr: Local storage
      sr_uuid: 0af1245e-bdb0-ba33-1446-57a962ec4075
      vbd_userdevice: '0'
    - name: testvm_11-1
      name_desc: ''
      os_device: xvdb
      size: 42949672960
      sr: Local storage
      sr_uuid: 0af1245e-bdb0-ba33-1446-57a962ec4075
      vbd_userdevice: '1'
    domid: '56'
    folder: ''
    hardware:
      memory_mb: 8192
      num_cpu_cores_per_socket: 2
      num_cpus: 4
    home_server: ''
    is_template: false
    name: testvm_11
    name_desc: ''
    networks:
    - gateway: 192.168.0.254
      gateway6: fc00::fffe
      ip: 192.168.0.200
      ip6:
      - fe80:0000:0000:0000:e9cb:625a:32c5:c291
      - fc00:0000:0000:0000:0000:0000:0000:0001
      mac: ba:91:3a:48:20:76
      mtu: '1500'
      name: Pool-wide network associated with eth1
      netmask: 255.255.255.128
      prefix: '25'
      prefix6: '64'
      vif_device: '0'
    other_config:
      base_template_name: Windows Server 2016 (64-bit)
      import_task: OpaqueRef:e43eb71c-45d6-5351-09ff-96e4fb7d0fa5
      install-methods: cdrom
      instant: 'true'
      mac_seed: f83e8d8a-cfdc-b105-b054-ef5cb416b77e
    platform:
      acpi: '1'
      apic: 'true'
      cores-per-socket: '2'
      device_id: '0002'
      hpet: 'true'
      nx: 'true'
      pae: 'true'
      timeoffset: '-25200'
      vga: std
      videoram: '8'
      viridian: 'true'
      viridian_reference_tsc: 'true'
      viridian_time_ref_count: 'true'
    state: poweredon
    uuid: e3c0b2d5-5f05-424e-479c-d3df8b3e7cda
    xenstore_data:
      vm-data: ''
  type: dict