Skip to content

Commit 2f47f93

Browse files
authored
Merge pull request #36 from raspbeguy/rbd-volume-pool
RBD volume pool support
2 parents a6dcc39 + d9be1f9 commit 2f47f93

File tree

10 files changed

+98
-13
lines changed

10 files changed

+98
-13
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Role Variables
1515
`libvirt_host_pools` is a list of pools to define and start. Each item
1616
should be a dict containing the following items:
1717
- `name` The name of the pool.
18-
- `type` The type of the pool, currently only `dir` and `logical` are
18+
- `type` The type of the pool, currently only `dir`, `logical` and `rbd` are
1919
supported. `lvm2` is supported as an alias for `logical`, but this alias is
2020
deprecated and will be removed in a future release.
2121
- `capacity` The capacity, in bytes, of the pool. (optional)
@@ -24,9 +24,13 @@ should be a dict containing the following items:
2424
integer **without** a leading zero; for example: `mode: 755`. (only `dir`)
2525
- `owner` The owner of the pool. (only `dir`)
2626
- `group` The group of the pool. (only `dir`)
27-
- `source` The name of the volume group. (only when type is `logical`)
27+
- `source` The name of the volume group (when type is `logical`) or RBD pool
28+
(when type is `rbd`).
2829
- `pvs` A list of physical volumes the volume group consists of. (only when
30+
- `hosts` The list of the Ceph monitors IPs or hostnames. (only `rbd`)
2931
type is `logical`)
32+
- `username` The username used for RADOS authentification. (only `rbd`)
33+
- `passphrase` The passphrase used for RADOS authentification. (only `rbd`)
3034

3135
`libvirt_host_networks` is a list of networks to define and start. Each item
3236
should be a dict containing the following items:
@@ -108,6 +112,16 @@ Example Playbook
108112
target: /dev/vg1
109113
pvs:
110114
- /dev/sda3
115+
- name: rbd-pool
116+
type: rbd
117+
source: rbd
118+
hosts:
119+
- 192.168.42.200
120+
- 192.168.42.204
121+
- 192.168.42.208
122+
username: admin
123+
passphrase: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
124+
111125
libvirt_host_networks:
112126
- name: br-example
113127
mode: bridge

tasks/install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
package:
3939
name: "{{ package }}"
4040
state: present
41-
with_items: "{{ libvirt_host_qemu_emulators }}"
41+
loop: "{{ libvirt_host_qemu_emulators | flatten(levels=1) }}"
4242
# NOTE(mgoddard): CentOS 8 does not provide separate packages per-emulator.
4343
when: ansible_os_family != "RedHat" or ansible_distribution_major_version | int == 7
4444
register: result

tasks/networks.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
with_items: "{{ libvirt_host_networks }}"
99
become: True
1010

11-
- name: Ensure libvirt networks are active
11+
- name: Ensure libvirt networks are started on boot
1212
virt_net:
1313
name: "{{ item.name }}"
14-
state: active
14+
autostart: yes
1515
uri: "{{ libvirt_host_uri | default(omit, true) }}"
1616
with_items: "{{ libvirt_host_networks }}"
1717
become: True
1818

19-
- name: Ensure libvirt networks are started on boot
19+
- name: Ensure libvirt networks are active
2020
virt_net:
2121
name: "{{ item.name }}"
22-
autostart: yes
22+
state: active
2323
uri: "{{ libvirt_host_uri | default(omit, true) }}"
2424
with_items: "{{ libvirt_host_networks }}"
2525
become: True

tasks/pools.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,45 @@
77
mode: "{{ item.mode|int(base=8) }}"
88
state: directory
99
when: item.type == "dir"
10-
with_items: "{{ libvirt_host_pools }}"
10+
loop: "{{ libvirt_host_pools | flatten(levels=1) }}"
1111
become: True
1212

1313
- name: Ensure libvirt LVM storage pool directories exist
1414
lvg:
1515
vg: "{{ item.source }}"
1616
pvs: "{{ item.pvs }}"
1717
when: item.type in ["lvm2", "logical"]
18-
with_items: "{{ libvirt_host_pools }}"
18+
loop: "{{ libvirt_host_pools | flatten(levels=1) }}"
1919
become: True
2020

21+
- include_tasks:
22+
file: rbd.yml
23+
apply:
24+
become: True
25+
when: item.type == "rbd"
26+
loop: "{{ libvirt_host_pools | flatten(levels=1) }}"
27+
2128
- name: Ensure libvirt storage pools are defined
2229
virt_pool:
2330
name: "{{ item.name }}"
2431
command: define
2532
xml: "{{ item.xml | default(lookup('template', 'pool.xml.j2')) }}"
2633
uri: "{{ libvirt_host_uri | default(omit, true) }}"
27-
with_items: "{{ libvirt_host_pools }}"
34+
loop: "{{ libvirt_host_pools | flatten(levels=1) }}"
2835
become: True
2936

3037
- name: Ensure libvirt storage pools are active
3138
virt_pool:
3239
name: "{{ item.name }}"
3340
state: active
3441
uri: "{{ libvirt_host_uri | default(omit, true) }}"
35-
with_items: "{{ libvirt_host_pools }}"
42+
loop: "{{ libvirt_host_pools | flatten(levels=1) }}"
3643
become: True
3744

3845
- name: Ensure libvirt storage pools are started on boot
3946
virt_pool:
4047
name: "{{ item.name }}"
4148
autostart: yes
4249
uri: "{{ libvirt_host_uri | default(omit, true) }}"
43-
with_items: "{{ libvirt_host_pools }}"
50+
loop: "{{ libvirt_host_pools | flatten(levels=1) }}"
4451
become: True

tasks/rbd.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
3+
- name: Install additional packages for rbd support
4+
package:
5+
name: "{{ libvirt_host_packages_rbd_volume_pool | flatten(levels=1) }}"
6+
state: present
7+
notify: restart libvirt
8+
9+
- name: Create temporary file for Ceph secret
10+
tempfile:
11+
state: file
12+
suffix: .xml
13+
register: secret_tempfile
14+
15+
- name: Send Ceph secret
16+
template:
17+
src: ceph_secret.xml.j2
18+
dest: "{{ secret_tempfile.path }}"
19+
20+
- name: Define Ceph secret
21+
command: "virsh secret-define {{ secret_tempfile.path }}"
22+
23+
- name: Set Ceph secret value
24+
command: "virsh secret-set-value {{ item.name | to_uuid }} {{ item.passphrase }}"
25+
26+
- name: Delete temporary file
27+
file:
28+
path: "{{ secret_tempfile.path }}"
29+
state: absent
30+
31+
- name: Flush handlers
32+
meta: flush_handlers
33+
34+

templates/ceph_secret.xml.j2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<secret ephemeral='no' private='yes'>
2+
<uuid>{{ item.name | to_uuid }}</uuid>
3+
<description>{{ item.name }} pool secret</description>
4+
<usage type='ceph'>
5+
<name>{{ item.name }}</name>
6+
</usage>
7+
</secret>

templates/pool.xml.j2

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@
77
{% if 'capacity' in item %}
88
<capacity>{{ item.capacity }}</capacity>
99
{% endif %}
10-
{% if item.type in ['logical', 'lvm2', 'zfs'] %}
10+
{% if item.type in ['logical', 'lvm2', 'zfs', 'rbd'] %}
1111
<source>
1212
<name>{{ item.source }}</name>
1313
{% if item.type in ['logical', 'lvm2'] %}
1414
<format type='lvm2'/>
1515
{% endif %}
16+
{% if item.type == 'rbd' %}
17+
{% for host in item.hosts %}
18+
<host name='{{ host }}' />
19+
{% endfor %}
20+
<auth type='ceph' username='{{ item.username }}'>
21+
<secret usage='{{ item.name }}'/>
22+
</auth>
23+
{% endif %}
1624
</source>
1725
{% endif %}
1826
{% if item.type != 'zfs' %}

vars/Archlinux.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@ libvirt_host_libvirt_packages: >
1818
(libvirt_host_packages_efi if libvirt_host_enable_efi_support else []) | unique
1919
}}
2020
21+
# Packages for RBD volume pool support
22+
libvirt_host_packages_rbd_volume_pool:
23+
- libvirt-storage-rbd
24+
- qemu-block-rbd
25+
2126
# These are passed to the lineinfile module to customize configuration files
2227
libvirt_host_lineinfile_extra_rules: []

vars/Debian.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@ libvirt_host_libvirt_packages: >
2626
(libvirt_host_packages_efi if libvirt_host_enable_efi_support else []) | unique
2727
}}
2828
29+
# Packages for RBD volume pool support
30+
libvirt_host_packages_rbd_volume_pool:
31+
- libvirt-daemon-driver-storage-rbd
32+
- qemu-block-extra
33+
2934
# These are passed to the lineinfile module to customize configuration files
3035
libvirt_host_lineinfile_extra_rules: []

vars/RedHat.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ libvirt_host_libvirt_packages: >
1818
(libvirt_host_packages_efi if libvirt_host_enable_efi_support else []) | unique
1919
}}
2020
21+
# Packages for RBD volume pool support
22+
libvirt_host_packages_rbd_volume_pool:
23+
- libvirt-daemon-driver-storage-rbd
24+
- qemu-kvm-block-rbd
25+
2126
libvirt_host_custom_yum_repos_efi:
2227
# Add custom repository as OVMF package seems to be broken
2328
- name: qemu-firmware-jenkins

0 commit comments

Comments
 (0)