Skip to content

Commit 435ea81

Browse files
author
jovial
authored
Merge pull request #11 from jovial/ubuntu
Support Debian based GNU/Linux distributions
2 parents 3975c10 + e5a3483 commit 435ea81

File tree

6 files changed

+53
-6
lines changed

6 files changed

+53
-6
lines changed

files/virt_volume.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ if [[ $result -ne 0 ]]; then
5959
exit $result
6060
fi
6161

62-
# Change the ownership of the volume to qemu. Without doing this libvirt cannot
63-
# access the volume.
64-
output=$(chown qemu:qemu $output 2>1)
62+
# Change the ownership of the volume to VOLUME_OWNER:VOLUME_GROUP if
63+
# these environmental variables are defined. Without doing this libvirt
64+
# cannot access the volume on RedHat based GNU/Linux distributions.
65+
existing_owner="$(stat --format '%U' "$output")"
66+
existing_group="$(stat --format '%G' "$output")"
67+
new_owner="${VOLUME_OWNER:-$existing_owner}"
68+
new_group="${VOLUME_GROUP:-$existing_group}"
69+
output=$(chown "$new_owner":"$new_group" $output 2>1)
6570
result=$?
6671
if [[ $result -ne 0 ]]; then
67-
echo "Failed to change ownership of the volume to qemu"
72+
echo "Failed to change ownership of the volume to $new_owner:$new_group"
6873
echo "$output"
6974
virsh vol-delete --pool $POOL --vol $NAME
7075
exit $result

meta/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ galaxy_info:
1111
- name: EL
1212
versions:
1313
- 7
14+
- name: Ubuntu
15+
versions:
16+
- all
17+
- name: Debian
18+
versions:
19+
- all
1420
galaxy_tags:
1521
- cloud
1622
- kvm

tasks/vm.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
---
2+
- name: Gather os specific variables
3+
include_vars: "{{ item }}"
4+
with_first_found:
5+
- files:
6+
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
7+
- "{{ ansible_distribution }}.yml"
8+
- "{{ ansible_os_family }}.yml"
9+
skip: true
10+
tags: vars
11+
212
- name: Ensure the VM console log directory exists
313
file:
414
path: "{{ console_log_path | dirname }}"
515
state: directory
6-
owner: qemu
7-
group: qemu
16+
owner: "{{ libvirt_vm_log_owner }}"
17+
group: "{{ libvirt_vm_log_owner }}"
818
recurse: true
919
mode: 0770
1020
when: console_log_enabled | bool

tasks/volumes.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
---
2+
- name: Gather os specific variables
3+
include_vars: "{{ item }}"
4+
with_first_found:
5+
- files:
6+
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
7+
- "{{ ansible_distribution }}.yml"
8+
- "{{ ansible_os_family }}.yml"
9+
tags: vars
10+
211
- name: Ensure remote images are downloaded
312
get_url:
413
url: "{{ item }}"
@@ -24,6 +33,7 @@
2433
{{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}
2534
{% endif %}
2635
with_items: "{{ volumes }}"
36+
environment: "{{ libvirt_vm_volume_creation_env }}"
2737
register: volume_result
2838
changed_when:
2939
- volume_result is success

vars/Debian.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
3+
# Who owns the serial console logs in console_log_path
4+
libvirt_vm_log_owner: libvirt-qemu
5+
6+
# The environment passed to virt_volume.sh
7+
libvirt_vm_volume_creation_env: {}

vars/RedHat.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
3+
# Who owns the serial console logs in console_log_path
4+
libvirt_vm_log_owner: qemu
5+
6+
# The environment passed to virt_volume.sh
7+
libvirt_vm_volume_creation_env:
8+
VOLUME_GROUP: qemu
9+
VOLUME_OWNER: qemu

0 commit comments

Comments
 (0)