An ansible role to import virtual machine with the virt-install import
command
This role depends on the virt-install
command.
The role will install the required packages on most GNU/Linux distributions.
- Archlinux
- AlmaLinux
- Debian
- Centos
- Fedora
- RedHat
- Rocky
- Suse
- Ubuntu
-
install
All installation-related tasks are defined in the
install
playbook. This allows you to install the required packages and start/enable the required service withtasks_from
in theinclude_role
,import_role
, โฆ ansible modules.See example below.
-
install
Install the required packages.
- virt_install_import: "namespace"
- name: required. The name of the virtual machine
- autostart: optional default: true. Enable autostart.
- wait: optional default: 0. The
--wait
option for thevirt-install
command. A negative value will wait still the virtmachine is shutdown. 0 will just start the virtual machine and disconnect. - memory: optional, default 1024 The virtual machine memory
- vcpu: optional, default 1. The number of virtual cpu cores.
- virt_type: optional, default: kvm. The hypervisor type.
- graphics: optional, default: none. The graphical display configuration.
- os_type: optional, default: not defined. The operating system type.
- os_variant: optional, default: not defined. The operating system variant.
- network: optional, default: not defined. The network string
- disks: optional, default: not defined. The disk strings.
None
---
- name: Install libvirt & co
gather_facts: true
hosts: all
become: true
tasks:
- name: Install the requirements
include_role:
name: "{{ item }}"
tasks_from:
install
with_items:
- stafwag.libvirt
- stafwag.qemu_img
- stafwag.cloud_localds
- stafwag.virt_install_import
tags:
- install
---
- name: Import a virtual machine
gather_facts: no
become: true
hosts: localhost
roles:
- role: stafwag.virt_install_import
vars:
virt_install_import:
wait: -1
name: tstdebian2
os_type: Linux
os_variant: debian10
network: network:default
graphics: spice
disks:
- /var/lib/libvirt/images/tstdebian2.qcow2,device=disk
- /var/lib/libvirt/images/tstdebian2_cloudinit.iso,device=cdrom
MIT/BSD
Created by Staf Wagemakers, email: [email protected], website: http://www.wagemakers.be.