rhjhunt.libvirt_vm
libvirt-vm
This is an Ansible role for setting up a virtual machine (VM) using libvirt on a RHEL/CentOS KVM hypervisor.
Requirements
- Ansible version 2.9 or later
- Red Hat Enterprise Linux (RHEL) or CentOS version 7 or 8
Role Variables
Here are the variables you can use with this role.
Role Variable | Required | Default | Description |
---|---|---|---|
libvirt_vm_ip |
❌ | Public IP address for the libvirt VM | |
libvirt_vm_hostname |
✅ | Fully Qualified Domain Name (FQDN) of the VM | |
libvirt_vm_root_pwd |
✅ | Password for the root user | |
libvirt_vm_base_img |
✅ | Name of the base image | |
libvirt_vm_storage_pool |
❌ | default |
Storage pool for libvirt |
libvirt_vm_network |
✅ | Network type for the libvirt VM | |
libvirt_vm_vcpus |
❌ | 1 |
Number of virtual CPUs for the VM |
libvirt_vm_ram |
❌ | 1024 |
Amount of RAM in megabytes |
libvirt_vm_os_image_name |
❌ | {{ libvirt_vm_hostname }} |
Name of the VM image |
libvirt_vm_os_image_size |
❌ | 10G |
Size of the VM's operating system image |
libvirt_vm_os_variant |
❌ | rhel8.1 |
Operating system variant for libvirt |
libvirt_vm_nics |
✅ | Example in playbook | Configuration for the VM's network interface |
Dependencies
No additional dependencies are required.
Example Playbook
Here’s an example of how to create a libvirt VM:
- hosts: hypervisor
tags: provision
vars:
libvirt_vm_hostname: "vm.example.com"
libvirt_vm_root_pwd: "Pa$$w0rD!"
libvirt_vm_base_img: rhel-guest-image-8.qcow2
libvirt_vm_storage_pool: "default"
libvirt_vm_network: "bridge=br0,model=virtio"
libvirt_vm_vcpus: "2"
libvirt_vm_ram: "4096"
libvirt_vm_os_image_name: "{{ libvirt_vm_hostname }}"
libvirt_vm_os_image_size: "20G"
libvirt_vm_os_variant: "rhel8.1"
libvirt_vm_nics:
- name: eth0
bootproto: static
onboot: yes
ip: "{{ libvirt_vm_ip }}"
prefix: "24"
gateway: "192.168.122.1"
dns_server: "192.168.122.1"
tasks:
- name: Create a libvirt VM
include_role:
name: rhjhunt.libvirt_vm
You can also set the libvirt VM to use a DHCP address:
- hosts: hypervisor
tags: provision
vars:
libvirt_vm_hostname: "vm.example.com"
libvirt_vm_root_pwd: "Pa$$w0rD!"
libvirt_vm_base_img: rhel-guest-image-8.qcow2
libvirt_vm_storage_pool: "default"
libvirt_vm_network: "bridge=br0,model=virtio"
libvirt_vm_vcpus: "2"
libvirt_vm_ram: "4096"
libvirt_vm_os_image_name: "{{ libvirt_vm_hostname }}"
libvirt_vm_os_image_size: "20G"
libvirt_vm_os_variant: "rhel8.1"
libvirt_vm_nics:
- name: eth0
bootproto: dhcp
onboot: yes
tasks:
- name: Create a libvirt VM
include_role:
name: rhjhunt.libvirt_vm
License
This role is licensed under GPLv3.
Author Information
Created by Jacob Hunt (jhunt@redhat.com).
Installa
ansible-galaxy install rhjhunt.libvirt_vm
Licenza
gpl-3.0
Download
73
Proprietario