From: cel@kernel.org
To: <kdevops@lists.linux.dev>
Cc: Chuck Lever <chuck.lever@oracle.com>
Subject: [RFC PATCH 1/5] guestfs: Replace scripts/destroy_guestfs.sh with an Ansible playbook
Date: Thu, 22 May 2025 09:31:33 -0400 [thread overview]
Message-ID: <20250522133137.989457-2-cel@kernel.org> (raw)
In-Reply-To: <20250522133137.989457-1-cel@kernel.org>
From: Chuck Lever <chuck.lever@oracle.com>
Start to make use of the Ansible libvirt module to handle libvirt
guest configuration, and replace the open-coded loop over the
content of guestfs/kdevops_nodes.yml.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
.gitignore | 1 +
playbooks/guestfs.yml | 7 +++++
playbooks/roles/guestfs/tasks/destroy.yml | 32 ++++++++++++++++++++
playbooks/roles/guestfs/tasks/main.yml | 6 ++++
scripts/destroy_guestfs.sh | 36 -----------------------
scripts/guestfs.Makefile | 6 ++--
6 files changed, 50 insertions(+), 38 deletions(-)
create mode 100644 playbooks/guestfs.yml
create mode 100644 playbooks/roles/guestfs/tasks/destroy.yml
create mode 100644 playbooks/roles/guestfs/tasks/main.yml
delete mode 100755 scripts/destroy_guestfs.sh
diff --git a/.gitignore b/.gitignore
index f51213a59ad9..0e3998485a36 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@
.provisioned_once*
guestfs/
+!playbooks/roles/guestfs/
linux/
!workflows/linux/
diff --git a/playbooks/guestfs.yml b/playbooks/guestfs.yml
new file mode 100644
index 000000000000..8bb496e0f05a
--- /dev/null
+++ b/playbooks/guestfs.yml
@@ -0,0 +1,7 @@
+---
+- name: Provision target nodes with libvirt/guestfs
+ gather_facts: false
+ connection: local
+ hosts: all
+ roles:
+ - role: guestfs
diff --git a/playbooks/roles/guestfs/tasks/destroy.yml b/playbooks/roles/guestfs/tasks/destroy.yml
new file mode 100644
index 000000000000..e26aacde4cff
--- /dev/null
+++ b/playbooks/roles/guestfs/tasks/destroy.yml
@@ -0,0 +1,32 @@
+---
+- name: Destroy each target node
+ community.libvirt.virt:
+ name: "{{ inventory_hostname }}"
+ command: "destroy"
+ uri: "{{ libvirt_uri }}"
+ failed_when: false # Do not fail if the target node is not currently running
+
+- name: Undefine each target node
+ community.libvirt.virt:
+ name: "{{ inventory_hostname }}"
+ command: "undefine"
+ uri: "{{ libvirt_uri }}"
+ force: true
+ failed_when: false # Do not fail if the target node is not currently defined
+
+- name: Remove per-node configuration files
+ ansible.builtin.file:
+ path: "{{ item }}"
+ state: absent
+ loop:
+ - "{{ guestfs_path }}/{{ inventory_hostname }}"
+ - "{{ kdevops_storage_pool_path }}/guestfs/{{ inventory_hostname }}"
+
+- name: Remove global configuration files
+ run_once: true
+ ansible.builtin.file:
+ path: "{{ item }}"
+ state: absent
+ loop:
+ - "{{ kdevops_ssh_config }}"
+ - "{{ topdir_path }}/{{ kdevops_nodes }}"
diff --git a/playbooks/roles/guestfs/tasks/main.yml b/playbooks/roles/guestfs/tasks/main.yml
new file mode 100644
index 000000000000..60d4ffd40a20
--- /dev/null
+++ b/playbooks/roles/guestfs/tasks/main.yml
@@ -0,0 +1,6 @@
+---
+- name: Shut down and destroy each target node
+ tags:
+ - destroy
+ ansible.builtin.import_tasks:
+ file: "{{ role_path }}/tasks/destroy.yml"
diff --git a/scripts/destroy_guestfs.sh b/scripts/destroy_guestfs.sh
deleted file mode 100755
index dfbb4f15f4ca..000000000000
--- a/scripts/destroy_guestfs.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: copyleft-next-0.3.1
-
-[ -z "${TOPDIR}" ] && TOPDIR='.'
-source ${TOPDIR}/.config
-source ${TOPDIR}/scripts/lib.sh
-
-export LIBVIRT_DEFAULT_URI=$CONFIG_LIBVIRT_URI
-
-STORAGEDIR="${CONFIG_LIBVIRT_STORAGE_POOL_PATH}/${CONFIG_KDEVOPS_STORAGE_POOL_USER}/guestfs"
-GUESTFSDIR="${TOPDIR}/guestfs"
-
-if [ -f "$GUESTFSDIR/kdevops_nodes.yaml" ]; then
- # FIXME: is there a yaml equivalent to jq ?
- grep -e '^ - name: ' "${GUESTFSDIR}/kdevops_nodes.yaml" | sed 's/^ - name: //' | while read name
- do
- domstate=$(virsh domstate $name 2>/dev/null)
- if [ $? -eq 0 ]; then
- if [ "$domstate" = 'running' ]; then
- virsh destroy $name
- fi
- virsh undefine --nvram $name
- fi
- rm -rf "$GUESTFSDIR/$name"
- rm -rf "$STORAGEDIR/$name"
- ssh-keygen -q -f ~/.ssh/known_hosts -R $name 1> /dev/null 2>&1
- done
-fi
-
-if [[ "$CONFIG_TOPDIR_PATH_HAS_SHA256SUM" == "y" ]]; then
- rm -f ~/.ssh/config_kdevops_$CONFIG_TOPDIR_PATH_SHA256SUM
-else
- rm -f ~/.ssh/config_kdevops_$CONFIG_KDEVOPS_HOSTS_PREFIX
-fi
-rm -f $GUESTFSDIR/.provisioned_once
-rm -f $GUESTFSDIR/kdevops_nodes.yaml
diff --git a/scripts/guestfs.Makefile b/scripts/guestfs.Makefile
index 8d4aac3e3669..5d355ec70f8c 100644
--- a/scripts/guestfs.Makefile
+++ b/scripts/guestfs.Makefile
@@ -93,9 +93,11 @@ status_guestfs:
PHONY += status_guestfs
destroy_guestfs:
- $(Q)$(TOPDIR)/scripts/destroy_guestfs.sh
+ $(Q)ansible-playbook $(ANSIBLE_VERBOSE) \
+ -i hosts playbooks/guestfs.yml \
+ --extra-vars=@./extra_vars.yaml \
+ --tags destroy
$(Q)rm -f $(KDEVOPS_PROVISIONED_SSH) $(KDEVOPS_PROVISIONED_DEVCONFIG)
-
PHONY += destroy_guestfs
cleancache:
--
2.49.0
next prev parent reply other threads:[~2025-05-22 13:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 13:31 [RFC PATCH 0/5] Convert bringup_guestfs to a single Ansible role cel
2025-05-22 13:31 ` cel [this message]
2025-05-22 17:02 ` [RFC PATCH 1/5] guestfs: Replace scripts/destroy_guestfs.sh with an Ansible playbook Luis Chamberlain
2025-05-22 17:03 ` Chuck Lever
2025-05-22 13:31 ` [RFC PATCH 2/5] Move the guestfs install-deps to the guestfs playbook cel
2025-05-22 17:07 ` Luis Chamberlain
2025-05-22 17:13 ` Chuck Lever
2025-05-22 17:16 ` Luis Chamberlain
2025-05-22 13:31 ` [RFC PATCH 3/5] guestfs: Move console-related steps to guestfs role cel
2025-05-22 17:09 ` Luis Chamberlain
2025-05-22 17:11 ` Chuck Lever
2025-05-22 17:15 ` Luis Chamberlain
2025-05-22 13:31 ` [RFC PATCH 4/5] guestfs: Move check-config, network, and storage-pool tags cel
2025-05-22 13:31 ` [RFC PATCH 5/5] guestfs: Convert part of scripts/bringup_guestfs.sh to Ansible cel
2025-05-22 17:14 ` Luis Chamberlain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250522133137.989457-2-cel@kernel.org \
--to=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=kdevops@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.