public inbox for kdevops@lists.linux.dev
 help / color / mirror / Atom feed
From: Chuck Lever <cel@kernel.org>
To: <kdevops@lists.linux.dev>
Cc: Chuck Lever <chuck.lever@oracle.com>,
	Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH v2 01/12] guestfs: Replace scripts/destroy_guestfs.sh with an Ansible playbook
Date: Fri, 30 May 2025 13:52:18 -0400	[thread overview]
Message-ID: <20250530175229.489925-2-cel@kernel.org> (raw)
In-Reply-To: <20250530175229.489925-1-cel@kernel.org>

From: Chuck Lever <chuck.lever@oracle.com>

Use Ansible for destroying libvirt-based target nodes. This replaces
an open-coded loop over the target node hosts, and makes the destroy
target more idempotent.

Also, this change is a prerequisite to making guestfs and terraform
manage their ssh key material in the same way, eventually.

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
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/guestfs.Makefile                  |  6 +++--
 5 files changed, 50 insertions(+), 2 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

diff --git a/.gitignore b/.gitignore
index 45113a669390..706ef3fca950 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/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


  reply	other threads:[~2025-05-30 17:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-30 17:52 [PATCH v2 00/12] Convert bringup_guestfs to a single Ansible role Chuck Lever
2025-05-30 17:52 ` Chuck Lever [this message]
2025-05-30 17:52 ` [PATCH v2 02/12] Move the guestfs install-deps to the guestfs playbook Chuck Lever
2025-05-30 17:52 ` [PATCH v2 03/12] guestfs: Do not use the config-check tag Chuck Lever
2025-05-30 17:52 ` [PATCH v2 04/12] guestfs: Add a "bringup" tag to the guestfs role Chuck Lever
2025-05-30 17:52 ` [PATCH v2 05/12] guestfs: Copy "network" tag steps to " Chuck Lever
2025-05-30 17:52 ` [PATCH v2 06/12] guestfs: Move the QEMU_GROUP check Chuck Lever
2025-05-30 17:52 ` [PATCH v2 07/12] Add a base-image role Chuck Lever
2025-05-30 17:52 ` [PATCH v2 08/12] guestfs: Convert scripts/bringup_guestfs.sh to Ansible Chuck Lever
2025-05-30 17:52 ` [PATCH v2 09/12] guestfs: Move console-related steps to guestfs role Chuck Lever
2025-05-30 17:52 ` [PATCH v2 10/12] bringup_guestfs: Remove the role Chuck Lever
2025-05-30 17:52 ` [PATCH v2 11/12] scripts: Remove the bringup_guestfs.sh script Chuck Lever
2025-05-30 17:52 ` [PATCH v2 12/12] scripts: Remove the destroy_guestfs.sh script Chuck Lever
2025-06-03 19:29 ` [PATCH v2 00/12] Convert bringup_guestfs to a single Ansible role Luis Chamberlain
2025-06-04 14:29   ` Chuck Lever
2025-06-04 17:02     ` 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=20250530175229.489925-2-cel@kernel.org \
    --to=cel@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=kdevops@lists.linux.dev \
    --cc=mcgrof@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox