From 24e9812d5605caa5d6df2efadddf8f6cb438db0e Mon Sep 17 00:00:00 2001 From: Kostiantyn Kalynovskyi Date: Fri, 9 Apr 2021 17:34:54 +0000 Subject: [PATCH] Make storage playbooks idempotent Also this disables libvirt networking templates, untill we have a working template requirement. Change-Id: Id3098b3dc5eec15f41c30d5b656dd3bc9a632e42 --- vino-builder/assets/entrypoint.sh | 14 ++++++- .../roles/libvirt/tasks/create-network.yaml | 22 ++-------- .../roles/libvirt/tasks/create-storage.yaml | 41 ++----------------- .../playbooks/roles/libvirt/tasks/main.yml | 6 +-- 4 files changed, 22 insertions(+), 61 deletions(-) diff --git a/vino-builder/assets/entrypoint.sh b/vino-builder/assets/entrypoint.sh index d4ddc70..b089f50 100644 --- a/vino-builder/assets/entrypoint.sh +++ b/vino-builder/assets/entrypoint.sh @@ -14,6 +14,11 @@ set -ex +READINESS_CHECK_FILE="/tmp/healthy" + +## Remove healthy status before starting +[ -f "${READINESS_CHECK_FILE}" ] && rm ${READINESS_CHECK_FILE} + # wait for libvirt socket to be ready TIMEOUT=300 while [[ ! -e /var/run/libvirt/libvirt-sock ]]; do @@ -51,10 +56,15 @@ while [[ ${TIMEOUT} -gt 0 ]]; do done ansible-playbook -v \ - -e @/vino/spec \ -e @/var/lib/vino-builder/flavors/flavors.yaml \ -e @/var/lib/vino-builder/flavor-templates/flavor-templates.yaml \ -e @/var/lib/vino-builder/network-templates/network-templates.yaml \ -e @/var/lib/vino-builder/storage-templates/storage-templates.yaml \ -e @$DYNAMIC_DATA_FILE \ - /playbooks/vino-builder.yaml \ No newline at end of file + /playbooks/vino-builder.yaml + +touch ${READINESS_CHECK_FILE} + +while true; do + sleep infinity +done \ No newline at end of file diff --git a/vino-builder/assets/playbooks/roles/libvirt/tasks/create-network.yaml b/vino-builder/assets/playbooks/roles/libvirt/tasks/create-network.yaml index 6fdfe5e..d3e7b3d 100644 --- a/vino-builder/assets/playbooks/roles/libvirt/tasks/create-network.yaml +++ b/vino-builder/assets/playbooks/roles/libvirt/tasks/create-network.yaml @@ -14,29 +14,19 @@ # never re-define it - name: add networks defined if they do not already exist virt_net: - command: define + state: present # looks like setting name here is a redundant, the name is anyways taken from the template xml file, but should set it to make virt_pool module happy. name: "{{ item.name }}" xml: "{{ item.libvirtTemplate }}" uri: "{{ libvirt_uri }}" - when: 'item.name not in ansible_libvirt_networks' vars: nodebridgegw: ipam.bridge_ip -# Re-gather Facts will be available as 'ansible_libvirt_networks' -- name: re-gather facts on existing virsh networks +- name: activate the network virt_net: - command: facts - name: "" - uri: "{{ libvirt_uri }}" - ignore_errors: true - -- name: start the network - virt_net: - command: create + state: active name: "{{ item.name }}" uri: "{{ libvirt_uri }}" - when: item.name in ansible_libvirt_networks and ansible_libvirt_networks[item.name].state != "active" # these are idempotent so require no conditional checks - name: autostart the network @@ -44,9 +34,3 @@ autostart: yes name: "{{ item.name }}" uri: "{{ libvirt_uri }}" - -- name: activate the network - virt_net: - state: active - name: "{{ item.name }}" - uri: "{{ libvirt_uri }}" \ No newline at end of file diff --git a/vino-builder/assets/playbooks/roles/libvirt/tasks/create-storage.yaml b/vino-builder/assets/playbooks/roles/libvirt/tasks/create-storage.yaml index a2581cb..64dfd23 100644 --- a/vino-builder/assets/playbooks/roles/libvirt/tasks/create-storage.yaml +++ b/vino-builder/assets/playbooks/roles/libvirt/tasks/create-storage.yaml @@ -4,48 +4,15 @@ command: facts uri: "{{ libvirt_uri }}" -- name: Print value of ansible storage pools - debug: - msg: "Value of ansible_libvirt_pools is {{ ansible_libvirt_pools }}" - -- name: write out storage xml template - copy: content="{{item.libvirtTemplate}}" dest="/tmp/storage-{{item.name}}.xml" - -- name: define the storage pool - shell: "virsh pool-define /tmp/storage-{{item.name}}.xml" - -# Re-gather facts after definining additional pools available as 'ansible_libvirt_pools' -- name: re-gather facts on existing virsh pools after defining missing pools +- name: define storage the storage pool virt_pool: - command: facts - uri: "{{ libvirt_uri }}" - -- name: build the storage pool - virt_pool: - command: build - name: "{{ item.name }}" - uri: "{{ libvirt_uri }}" - when: item.name in ansible_libvirt_pools and ansible_libvirt_pools[item.name].state != "active" - -- name: start the storage pool - virt_pool: - command: create - name: "{{ item.name }}" - uri: "{{ libvirt_uri }}" - when: item.name in ansible_libvirt_pools and ansible_libvirt_pools[item.name].state != "active" - -# these are idempotent so require no conditional checks - -# TODO: we are not actually defining configs on the host -# for some reason we cannot do this -- name: autostart the storage pool - virt_pool: - autostart: yes + state: present name: "{{ item.name }}" uri: "{{ libvirt_uri }}" + xml: "{{item.libvirtTemplate}}" - name: activate the storage pool virt_pool: state: active name: "{{ item.name }}" - uri: "{{ libvirt_uri }}" \ No newline at end of file + uri: "{{ libvirt_uri }}" diff --git a/vino-builder/assets/playbooks/roles/libvirt/tasks/main.yml b/vino-builder/assets/playbooks/roles/libvirt/tasks/main.yml index a89f6e6..7e28516 100644 --- a/vino-builder/assets/playbooks/roles/libvirt/tasks/main.yml +++ b/vino-builder/assets/playbooks/roles/libvirt/tasks/main.yml @@ -10,9 +10,9 @@ # configure networks # ########################################## -- name: create network - include_tasks: create-network.yaml - loop: "{{ libvirtNetworks }}" +# - name: create network +# include_tasks: create-network.yaml +# loop: "{{ libvirtNetworks }}" ########################################## # configure domains #