Skip to content

Commit 8df508a

Browse files
committed
add rbd support
1 parent 57f915a commit 8df508a

File tree

8 files changed

+74
-5
lines changed

8 files changed

+74
-5
lines changed

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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
loop: "{{ libvirt_host_pools | flatten(levels=1) }}"
1919
become: True
2020

21+
- include: rbd.yml
22+
when: item.type == "rbd"
23+
loop: "{{ libvirt_host_pools | flatten(levels=1) }}"
24+
become: True
25+
2126
- name: Ensure libvirt storage pools are defined
2227
virt_pool:
2328
name: "{{ item.name }}"

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)