Kostiantyn Kalynovskyi 68157859a7 Add ansible roles for sushy and libvirt
This commit adds simple roles to manage:
 - libvirt service, domains, volumes, networks and pools.
 - redfish-emulator role installs sushy-tools from pip, together
   with support packages
Please note, that libvirt roles are not meant to be completely
idempotent, their main job is deploy temporary resources that for
ci and gating purposes, to be tore down afterwards. Roles are
specifically made to be simple to debug, and don't contain any
complex logic to make them portable, flexible or idempotent.

Change-Id: I2ff0138b5c95bea3445e242a2e5061651498f1ab
2020-01-13 23:08:11 +00:00

59 lines
2.0 KiB
YAML

- name: Get Scheme
set_fact:
image_scheme: "{{ libvirt_volume.image | urlsplit('scheme') }}"
when: "libvirt_volume.image is defined"
- name: Get Scheme
set_fact:
image_dest: "{{ libvirt_image_cache_path }}/{{ libvirt_volume.image | basename }}"
when: "libvirt_volume.image is defined"
- name: Ensure cache directories exist
file:
path: "{{ libvirt_image_cache_path }}"
state: directory
- name: Ensure remote images are downloaded
get_url:
url: "{{ libvirt_volume.image }}"
dest: "{{ image_dest }}"
checksum: "{{ libvirt_volume.checksum | default(omit) }}"
when: "image_scheme in libvirt_remote_scheme_list and libvirt_volume.image is defined"
- name: Ensure local images are copied
copy:
src: "{{ libvirt_volume.image }}"
dest: "{{ image_dest }}"
when: "image_scheme not in libvirt_remote_scheme_list and libvirt_volume.image is defined"
- name: "Create volume"
command: >-
virsh vol-create-as "{{ libvirt_volume.pool }}" \
--name "{{ libvirt_volume.name }}" \
--capacity "{{ libvirt_volume.size }}" \
--format "{{ libvirt_volume.format | default('qcow2') }}"
register: libvirt_create_volume
failed_when:
- "libvirt_create_volume.rc != 0"
- "'Failed to create vol' in libvirt_create_volume.stdout"
- "'exists already' not in libvirt_create_volume.stdout"
changed_when:
- "libvirt_create_volume.rc != 1"
- "'exists already' not in libvirt_create_volume.stdout"
- name: "Upload volume from downloaded image"
command: >-
virsh vol-upload --pool "{{ libvirt_volume.pool }}" --vol "{{ libvirt_volume.name }}" --file "{{ image_dest }}"
when:
- "libvirt_volume.image is defined"
- "libvirt_create_volume.rc == 0"
- name: "Resize volume after uploading from image"
command: >-
virsh vol-resize --vol "{{ libvirt_volume.name }}" --pool "{{ libvirt_volume.pool }}" --capacity "{{ libvirt_volume.size }}"
when:
- "libvirt_create_volume.rc == 0"
- "libvirt_volume.image is defined"