Skip to content

Support Debian based GNU/Linux distributions #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions files/virt_volume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,17 @@ if [[ $result -ne 0 ]]; then
exit $result
fi

# Change the ownership of the volume to qemu. Without doing this libvirt cannot
# access the volume.
output=$(chown qemu:qemu $output 2>1)
# Change the ownership of the volume to VOLUME_OWNER:VOLUME_GROUP if
# these environmental variables are defined. Without doing this libvirt
# cannot access the volume on RedHat based GNU/Linux distributions.
existing_owner="$(stat --format '%U' "$output")"
existing_group="$(stat --format '%G' "$output")"
new_owner="${VOLUME_OWNER:-$existing_owner}"
new_group="${VOLUME_GROUP:-$existing_group}"
output=$(chown "$new_owner":"$new_group" $output 2>1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could have just done

if [[ -n $VOLUME_GROUP ]] && [[ -n $VOLUME_OWNER ]]; then
  output=$(chown "$VOLUME_OWNER":"$VOLUME_GROUP" $output 2>1
fi

But this works.

result=$?
if [[ $result -ne 0 ]]; then
echo "Failed to change ownership of the volume to qemu"
echo "Failed to change ownership of the volume to $new_owner:$new_group"
echo "$output"
virsh vol-delete --pool $POOL --vol $NAME
exit $result
Expand Down
6 changes: 6 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ galaxy_info:
- name: EL
versions:
- 7
- name: Ubuntu
versions:
- all
- name: Debian
versions:
- all
galaxy_tags:
- cloud
- kvm
Expand Down
14 changes: 12 additions & 2 deletions tasks/vm.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
---
- name: Gather os specific variables
include_vars: "{{ item }}"
with_first_found:
- files:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
skip: true
tags: vars

- name: Ensure the VM console log directory exists
file:
path: "{{ console_log_path | dirname }}"
state: directory
owner: qemu
group: qemu
owner: "{{ libvirt_vm_log_owner }}"
group: "{{ libvirt_vm_log_owner }}"
recurse: true
mode: 0770
when: console_log_enabled | bool
Expand Down
10 changes: 10 additions & 0 deletions tasks/volumes.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
---
- name: Gather os specific variables
include_vars: "{{ item }}"
with_first_found:
- files:
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}.yml"
tags: vars

- name: Ensure remote images are downloaded
get_url:
url: "{{ item }}"
Expand All @@ -24,6 +33,7 @@
{{ libvirt_vm_image_cache_path }}/{{ item.image | basename }}
{% endif %}
with_items: "{{ volumes }}"
environment: "{{ libvirt_vm_volume_creation_env }}"
register: volume_result
changed_when:
- volume_result is success
Expand Down
7 changes: 7 additions & 0 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

# Who owns the serial console logs in console_log_path
libvirt_vm_log_owner: libvirt-qemu

# The environment passed to virt_volume.sh
libvirt_vm_volume_creation_env: {}
9 changes: 9 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

# Who owns the serial console logs in console_log_path
libvirt_vm_log_owner: qemu

# The environment passed to virt_volume.sh
libvirt_vm_volume_creation_env:
VOLUME_GROUP: qemu
VOLUME_OWNER: qemu