-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add play to ensure that no instaces are running on a compute node (#414)
Signed-off-by: Christian Berendt <[email protected]>
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
- name: Ensure no instances | ||
hosts: "{{ hosts_check_for_instances | default('compute') }}" | ||
|
||
tasks: | ||
- name: Get all instances defined in Libvirt | ||
community.docker.docker_container_exec: | ||
container: nova_libvirt | ||
command: virsh list --all --uuid | ||
register: defined_instances | ||
|
||
- name: Assert no instances are defined in Libvirt | ||
ansible.builtin.assert: | ||
that: | ||
- defined_instances.stdout | length == 0 | ||
fail_msg: "{{ defined_instances.stdout | length }} are still defined in Libvirt" | ||
success_msg: No instances defined in Libvirt | ||
|
||
# source: https://stackoverflow.com/questions/46515704/how-to-kill-a-running-process-using-ansible | ||
# NOTE: We use /bin/sh here as the default for the shell, so | ||
# set -o pipefail is not usable (Illegal option). Therefore, | ||
# we ignore the ansible-lint rule risky-shell-pipe at this | ||
# point. | ||
- name: Get running qemu processes | ||
ansible.builtin.shell: # noqa: risky-shell-pipe | ||
cmd: ps -ef | grep -v grep | grep -w qemu | awk '{print $2}' | ||
register: running_processes | ||
changed_when: false | ||
|
||
- name: Assert no qemu processes running | ||
ansible.builtin.assert: | ||
that: | ||
- running_processes.stdout | length == 0 | ||
fail_msg: "{{ running_processes.stdout | length }} qemu processes are still running" | ||
success_msg: No qemu processes running |