libvirt

Libvirt virtualization API and capabilities.

1,129,104 downloads

268 latest version

5.0 quality score

Version information

  • 1.0.3 (latest)
  • 1.0.2
  • 1.0.1
  • 1.0.0
  • 0.3.2
  • 0.3.1
  • 0.3.0
  • 0.2.3
  • 0.2.2
  • 0.2.1
  • 0.2.0
  • 0.1.1
  • 0.1.0
  • 0.0.1
released Feb 4th 2025
This version is compatible with:
  • Puppet Enterprise 2023.2.x, 2023.1.x, 2023.0.x, 2021.7.x, 2021.6.x, 2021.5.x, 2021.4.x, 2021.3.x, 2021.2.x, 2021.1.x, 2021.0.x, 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2017.1.x, 2016.5.x, 2016.4.x
  • Puppet >=2.7.20 <8.0.0
  • RedHat
    ,
    CentOS
    ,
    Debian
    ,
    Ubuntu

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'thias-libvirt', '1.0.3'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add thias-libvirt
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install thias-libvirt --version 1.0.3

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

thias/libvirt — version 1.0.3 Feb 4th 2025

puppet-libvirt

Overview

Libvirt module. Useful on minimal Red Hat Enterprise Linux and Debian/Ubuntu installations which need to be configured as KVM virtualization hosts.

  • libvirt : Main class to install, enable and configure libvirt.
  • libvirt::network : Definition to manage libvirt networks.

Examples

Use all of the module's defaults :

include '::libvirt'

Typical KVM/qemu host for virtualization :

class { '::libvirt':
  mdns_adv => false
}

Change even more defaults :

class { '::libvirt':
  defaultnetwork     => true,
  virtinst           => false,
  unix_sock_group    => 'wheel',
  unix_sock_rw_perms => '0770',
}

The module also allows the user to customize qemu parameters :

class { '::libvirt':
  qemu_vnc_listen => "0.0.0.0",
  qemu_vnc_sasl   => true,
  qemu_vnc_tls    => false,
}

Configure Kerberos authentication:

class { '::libvirt':
  listen_tls                => false,
  listen_tcp                => true,
  auth_tcp                  => 'sasl',
  sysconfig                 => {
    'LIBVIRTD_ARGS' => '--listen',
  },
  sasl2_libvirt_mech_list   => 'gssapi',
  sasl2_libvirt_keytab      => '/etc/libvirt/krb5.tab',
  qemu_vnc_listen           => "0.0.0.0",
  qemu_vnc_sasl             => true,
  qemu_vnc_tls              => false,
  sasl2_qemu_mech_list      => 'gssapi',
  sasl2_qemu_keytab         => '/etc/qemu/krb5.tab',
  sasl2_qemu_auxprop_plugin => 'sasldb',
}

Replace the default network with a PXE boot one :

class { '::libvirt':
  defaultnetwork => false, # This is the default
}

$dhcp = {
  'start'      => '192.168.122.2',
  'end'        => '192.168.122.254',
  'bootp_file' => 'pxelinux.0',
}
$ip = {
  'address' => '192.168.122.1',
  'netmask' => '255.255.255.0',
  'dhcp'    => $dhcp,
}

libvirt::network { 'pxe':
  forward_mode => 'nat',
  forward_dev  => 'virbr0',
  ip           => [ $ip ],
}

We also support IPv6: It has the same sematics as ip:

# $ip = same as above

$ipv6 = {
  address => '2001:db8:ca2:2::1',
  prefix  => '64',
}

libvirt::network { 'dual-stack':
  forward_mode => 'nat',
  forward_dev  => 'virbr0',
  ip           => [ $ip ],
  ipv6         => [ $ipv6 ],
}

While this might look a little convoluted in puppet code, this gives you the ability to specify networks in hiera, and then use create_resources() to generate them:

---
libvirt_networks:

  pxe:
    autostart:    true
    forward_mode: nat
    forward_dev:  virbr0
    ip:
      - address: 192.168.122.1
        netmask: 255.255.255.0
        dhcp:
          start: 192.168.122.2
          end:   192.168.122.254
          bootp_file: pxelinux.0
  direct:
    autostart:    true
    forward_mode: bridge
    forward_dev: br0
    forward_interfaces:
      - eth0

and then in your manifest:

$networks = hiera('libvirt_networks', [])
create_resources($networks, $your_defaults_for_a_network)

On Red Hat Enterprise Linux, you might want to also manage changes to the /etc/sysconfig/libvirtd file. In this case, you pass the key/value pairs of the variables to set inside the sysconfig hash :

class { '::libvirt':
  listen_tls => false,
  listen_tcp => true,
  sysconfig  => {
    'LIBVIRTD_ARGS'          => '--listen',
    'LIBVIRTD_NOFILES_LIMIT' => '4096',
  },
}

Native Types

Libvirt Storage Pools

Puppet Resource

Query all current pools: $ puppet resource libvirt_pool

Examples

  • Create a new directory pool :
libvirt_pool { 'mypool' :
  ensure   => present,
  type     => 'dir',
  active   => false,
  target   => '/tmp/pool-dir',
}

The above will define, build but not activate the pool.

By default a pool is activated ( same as active => true).

By default a pool is not autostarted (same as autostart => false).

  • Create a logical pool (lvm) and set the autostart flag :
libvirt_pool { 'lvm-pool' :
  ensure     => present,
  type       => 'logical',
  autostart  => true,
  sourcedev  => [ '/dev/sdb1', '/dev/sdc1' ],
  sourcename => 'vg',
  target     => '/dev/vg'
}
  • Remove the default pool :
libvirt_pool { 'default' :
  ensure => absent,
}