Make storage playbooks idempotent

Also this disables libvirt networking templates, untill we have a
working template requirement.

Change-Id: Id3098b3dc5eec15f41c30d5b656dd3bc9a632e42
This commit is contained in:
Kostiantyn Kalynovskyi 2021-04-09 17:34:54 +00:00
parent 88a2792eb5
commit 24e9812d56
4 changed files with 22 additions and 61 deletions

View File

@ -14,6 +14,11 @@
set -ex 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 # wait for libvirt socket to be ready
TIMEOUT=300 TIMEOUT=300
while [[ ! -e /var/run/libvirt/libvirt-sock ]]; do while [[ ! -e /var/run/libvirt/libvirt-sock ]]; do
@ -51,10 +56,15 @@ while [[ ${TIMEOUT} -gt 0 ]]; do
done done
ansible-playbook -v \ ansible-playbook -v \
-e @/vino/spec \
-e @/var/lib/vino-builder/flavors/flavors.yaml \ -e @/var/lib/vino-builder/flavors/flavors.yaml \
-e @/var/lib/vino-builder/flavor-templates/flavor-templates.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/network-templates/network-templates.yaml \
-e @/var/lib/vino-builder/storage-templates/storage-templates.yaml \ -e @/var/lib/vino-builder/storage-templates/storage-templates.yaml \
-e @$DYNAMIC_DATA_FILE \ -e @$DYNAMIC_DATA_FILE \
/playbooks/vino-builder.yaml /playbooks/vino-builder.yaml
touch ${READINESS_CHECK_FILE}
while true; do
sleep infinity
done

View File

@ -14,29 +14,19 @@
# never re-define it # never re-define it
- name: add networks defined if they do not already exist - name: add networks defined if they do not already exist
virt_net: 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. # 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 }}" name: "{{ item.name }}"
xml: "{{ item.libvirtTemplate }}" xml: "{{ item.libvirtTemplate }}"
uri: "{{ libvirt_uri }}" uri: "{{ libvirt_uri }}"
when: 'item.name not in ansible_libvirt_networks'
vars: vars:
nodebridgegw: ipam.bridge_ip nodebridgegw: ipam.bridge_ip
# Re-gather Facts will be available as 'ansible_libvirt_networks' - name: activate the network
- name: re-gather facts on existing virsh networks
virt_net: virt_net:
command: facts state: active
name: ""
uri: "{{ libvirt_uri }}"
ignore_errors: true
- name: start the network
virt_net:
command: create
name: "{{ item.name }}" name: "{{ item.name }}"
uri: "{{ libvirt_uri }}" 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 # these are idempotent so require no conditional checks
- name: autostart the network - name: autostart the network
@ -44,9 +34,3 @@
autostart: yes autostart: yes
name: "{{ item.name }}" name: "{{ item.name }}"
uri: "{{ libvirt_uri }}" uri: "{{ libvirt_uri }}"
- name: activate the network
virt_net:
state: active
name: "{{ item.name }}"
uri: "{{ libvirt_uri }}"

View File

@ -4,48 +4,15 @@
command: facts command: facts
uri: "{{ libvirt_uri }}" uri: "{{ libvirt_uri }}"
- name: Print value of ansible storage pools - name: define storage the storage pool
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
virt_pool: virt_pool:
command: facts state: present
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
name: "{{ item.name }}" name: "{{ item.name }}"
uri: "{{ libvirt_uri }}" uri: "{{ libvirt_uri }}"
xml: "{{item.libvirtTemplate}}"
- name: activate the storage pool - name: activate the storage pool
virt_pool: virt_pool:
state: active state: active
name: "{{ item.name }}" name: "{{ item.name }}"
uri: "{{ libvirt_uri }}" uri: "{{ libvirt_uri }}"

View File

@ -10,9 +10,9 @@
# configure networks # # configure networks #
########################################## ##########################################
- name: create network # - name: create network
include_tasks: create-network.yaml # include_tasks: create-network.yaml
loop: "{{ libvirtNetworks }}" # loop: "{{ libvirtNetworks }}"
########################################## ##########################################
# configure domains # # configure domains #