File tree Expand file tree Collapse file tree 10 files changed +202
-0
lines changed Expand file tree Collapse file tree 10 files changed +202
-0
lines changed Original file line number Diff line number Diff line change
1
+ Libvirt Host
2
+ ============
3
+
4
+ This role configures a host as a Libvirt/KVM hypervisor. It can also configure
5
+ storage pools and networks on the host.
6
+
7
+ Requirements
8
+ ------------
9
+
10
+ The host should have Virtualization Technology (VT) enabled.
11
+
12
+ Role Variables
13
+ --------------
14
+
15
+ ` libvirt_host_networks ` is a list of pools to define and start. Each item
16
+ should be a dict containing the following items:
17
+ - ` name ` The name of the pool.
18
+ - ` type ` The type of the pool, currently only ` dir ` is supported.
19
+ - ` capacity ` The capacity, in bytes, of the pool.
20
+ - ` path ` The absolute path to the pool's backing directory.
21
+ - ` mode ` The access mode of the pool.
22
+ - ` owner ` The owner of the pool.
23
+ - ` group ` The group of the pool.
24
+
25
+ ` libvirt_host_networks ` is a list of networks to define and start. Each item
26
+ should be a dict containing the following items:
27
+ - ` name ` The name of the network.
28
+ - ` mode ` The forwarding mode of the network, currently only ` bridge ` is
29
+ supported.
30
+ - bridge` The name of the bridge interface for this network.
31
+
32
+ Dependencies
33
+ ------------
34
+
35
+ None
36
+
37
+ Example Playbook
38
+ ----------------
39
+
40
+ ---
41
+ - name: Ensure that Libvirt is configured
42
+ hosts: all
43
+ roles:
44
+ - role: libvirt-host
45
+ libvirt_host_pools:
46
+ - name: my-pool
47
+ type: dir
48
+ capacity: 1024
49
+ path: /path/to/pool
50
+ mode: 0755
51
+ owner: my-user
52
+ group: my-group
53
+ libvirt_host_networks:
54
+ - name: br-example
55
+ mode: bridge
56
+ bridge: br-example
57
+
58
+ Author Information
59
+ ------------------
60
+
61
+ - Mark Goddard (
< [email protected] > )
Original file line number Diff line number Diff line change
1
+ ---
2
+ # List of pools to define and start.
3
+ # Each item should be a dict containing the following items:
4
+ # name: The name of the pool.
5
+ # type: The type of the pool, currently only 'dir' is supported.
6
+ # capacity: The capacity, in bytes, of the pool.
7
+ # path: The absolute path to the pool's backing directory.
8
+ # mode: The access mode of the pool.
9
+ # owner: The owner of the pool.
10
+ # group: The group of the pool.
11
+ libvirt_host_pools : []
12
+
13
+ # List of networks to define and start.
14
+ # Each item should be a dict containing the following items:
15
+ # name: The name of the network.
16
+ # mode: The forwarding mode of the network, currently only 'bridge' is
17
+ # supported.
18
+ # bridge: The name of the bridge interface for this network.
19
+ libvirt_host_networks : []
Original file line number Diff line number Diff line change
1
+ ---
2
+ galaxy_info :
3
+ author : Mark Goddard
4
+ description : >
5
+ Role to install and configure a host as a Libvirt/KVM hypervisor
6
+ company : StackHPC Ltd
7
+ license : Apache2
8
+ min_ansible_version : 2.0
9
+ platforms :
10
+ - name : EL
11
+ versions :
12
+ - 7
13
+ galaxy_tags :
14
+ - cloud
15
+ - kvm
16
+ - libvirt
17
+ - vm
18
+
19
+ dependencies : []
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : Ensure the libvirt package is installed
3
+ yum :
4
+ name : " {{ item }}"
5
+ state : installed
6
+ with_items :
7
+ - libvirt
8
+ - libvirt-daemon-kvm
9
+ - libvirt-python
10
+ - python-lxml
11
+ - qemu-kvm
12
+ become : True
13
+
14
+ - name : Ensure the libvirt daemon is started and enabled
15
+ service :
16
+ name : libvirtd
17
+ state : running
18
+ enabled : yes
19
+ become : True
Original file line number Diff line number Diff line change
1
+ ---
2
+ - include : validate.yml
3
+ - include : install.yml
4
+ - include : pools.yml
5
+ - include : networks.yml
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : Ensure libvirt networks are defined
3
+ virt_net :
4
+ name : " {{ item.name }}"
5
+ command : define
6
+ xml : " {{ item.xml | default(lookup('template', 'network.xml.j2')) }}"
7
+ with_items : " {{ libvirt_host_networks }}"
8
+ become : True
9
+
10
+ - name : Ensure libvirt networks are active
11
+ virt_net :
12
+ name : " {{ item.name }}"
13
+ state : active
14
+ with_items : " {{ libvirt_host_networks }}"
15
+ become : True
16
+
17
+ - name : Ensure libvirt networks are started on boot
18
+ virt_net :
19
+ name : " {{ item.name }}"
20
+ autostart : yes
21
+ with_items : " {{ libvirt_host_networks }}"
22
+ become : True
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : Ensure libvirt storage pool directories exist
3
+ file :
4
+ path : " {{ item.path }}"
5
+ owner : " {{ item.owner }}"
6
+ group : " {{ item.group }}"
7
+ mode : " {{ item.mode|int(base=8) }}"
8
+ state : directory
9
+ with_items : " {{ libvirt_host_pools }}"
10
+ become : True
11
+
12
+ - name : Ensure libvirt storage pools are defined
13
+ virt_pool :
14
+ name : " {{ item.name }}"
15
+ command : define
16
+ xml : " {{ item.xml | default(lookup('template', 'pool.xml.j2')) }}"
17
+ with_items : " {{ libvirt_host_pools }}"
18
+ become : True
19
+
20
+ - name : Ensure libvirt storage pools are active
21
+ virt_pool :
22
+ name : " {{ item.name }}"
23
+ state : active
24
+ with_items : " {{ libvirt_host_pools }}"
25
+ become : True
26
+
27
+ - name : Ensure libvirt storage pools are started on boot
28
+ virt_pool :
29
+ name : " {{ item.name }}"
30
+ autostart : yes
31
+ with_items : " {{ libvirt_host_pools }}"
32
+ become : True
Original file line number Diff line number Diff line change
1
+ ---
2
+ - name : Verify that Virtualization Technology (VT) is enabled
3
+ command : grep -c -E 'svm|vmx' /proc/cpuinfo
4
+ changed_when : False
5
+ failed_when : False
6
+ register : result
7
+
8
+ - name : Fail if Virtualization Technology (VT) is disabled
9
+ fail :
10
+ msg : >
11
+ Virtualization Technology (VT) is currently disabled. Please enable VT
12
+ before running this role again.
13
+ when : result.rc != 0
Original file line number Diff line number Diff line change
1
+ <network connections =' 1' >
2
+ <name >{{ item.name }}</name >
3
+ <forward mode =' {{ item.mode }}' />
4
+ <bridge name =' {{ item.bridge }}' />
5
+ </network >
Original file line number Diff line number Diff line change
1
+ <pool type =' {{ item.type }}' >
2
+ <name >{{ item.name }}</name >
3
+ <capacity unit =' bytes' >{{ item.capacity }}</capacity >
4
+ <target >
5
+ <path >{{ item.path }}</path >
6
+ </target >
7
+ </pool >
You can’t perform that action at this time.
0 commit comments