libvirt: Fix nova-libvirt-cleanup command

This change addresses an issue in the nova-libvirt-cleanup command,
added in I46854ed7eaf1d5b5e3ccd8531c963427848bdc99.

Check for rc=1 pgrep command, since a lack of matches is a pass.

Also, use bash for set -o pipefail.

Change-Id: Iffda0dfffce8768324ffec55e629134c70e2e996
This commit is contained in:
Mark Goddard 2022-03-30 12:29:09 +01:00
parent f993047f45
commit 188b328566

View File

@ -14,12 +14,14 @@
register: container_facts register: container_facts
- block: - block:
# NOTE(mgoddard): pgrep exit status 1 means no match.
- name: Check if there are any running VMs - name: Check if there are any running VMs
become: true become: true
shell: shell:
cmd: > cmd: >
set -o pipefail && set -o pipefail &&
pgrep -l qemu | awk '!/qemu-ga/ && !/qemu-img/ {print $1}' { pgrep -l qemu || test $? = 1; } | awk '!/qemu-ga/ && !/qemu-img/ {print $1}'
executable: /bin/bash
register: running_vms register: running_vms
- name: Fail if there are any running VMs - name: Fail if there are any running VMs