blob: a5de66b65277ff7d37520f006f2211327b756579 [file] [log] [blame]
---
# ============LICENSE_START=======================================================
# Copyright (C) 2019 The Nordix Foundation. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=========================================================
- name: Set path to the volume created
set_fact:
vm_volume_name: "{{ hostname }}-{{ disk.name }}.qcow2"
vm_vol_path_prefix: "{{ ansible_libvirt_pools[libvirt_storage_pool].path }}/{{ hostname }}"
- name: Delete volume '{{ vm_volume_name }}' for vm '{{ hostname }}'
command: >
virsh --connect {{ vm_libvirt_uri }}
vol-delete --pool {{ libvirt_storage_pool }} {{ vm_volume_name }}
ignore_errors: yes
- name: Create volume '{{ vm_volume_name }}' for vm '{{ hostname }}'
command: >
virsh --connect {{ vm_libvirt_uri }}
vol-create-as {{ libvirt_storage_pool }} {{ vm_volume_name }}
{{ disk.disk_capacity }} --format qcow2 {{ prealloc|default("") }}
- name: Pre-touch volume '{{ vm_volume_name }}' for vm '{{ hostname }}'
file:
state: touch
path: "{{ vm_vol_path_prefix }}-{{ disk.name }}.qcow2"
when: vm_libvirt_uri == 'qemu:///system'
# NOTE(TheJulia): CentOS default installs with an XFS root, and chattr
# fails to set +C on XFS. This could be more elegant, however the use
# case is for CI testing.
- name: Set copy-on-write for volume on non-CentOS systems
command: chattr +C {{ vm_vol_path_prefix }}-{{ disk.name }}.qcow2
ignore_errors: yes
when:
- ansible_distribution != 'CentOS'
- vm_libvirt_uri == 'qemu:///system'
# vim: set ts=2 sw=2 expandtab: