public inbox for kdevops@lists.linux.dev
 help / color / mirror / Atom feed
From: Daniel Gomez <da.gomez@kernel.org>
To: Luis Chamberlain <mcgrof@kernel.org>,
	 Chuck Lever <chuck.lever@oracle.com>
Cc: kdevops@lists.linux.dev, Daniel Gomez <da.gomez@samsung.com>
Subject: [PATCH] guestfs: port status script to Ansible with libvirt URI fix
Date: Wed, 17 Sep 2025 10:49:31 +0200	[thread overview]
Message-ID: <20250917-status-script-v1-1-4a792f9ca518@samsung.com> (raw)

From: Daniel Gomez <da.gomez@samsung.com>

Convert scripts/status_guestfs.sh shell script to Ansible implementation
in playbooks/roles/guestfs/tasks/status/main.yml. The new implementation:

- Uses proper libvirt_uri variable for LIBVIRT_DEFAULT_URI
- Integrates with DIY callback to show command output
- Provides idempotent Ansible approach with tagging support
- Fixes missing libvirt URI context that caused empty virsh output

Update scripts/guestfs.Makefile to call ansible-playbook with --tags status
instead of the shell script. Add missing output yaml to LIBVIRT_URI_PATH
for proper URI variable generation.

Generated-by: Claude AI
Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
The conversion in combination with the DIY stdout callback support [1]
results in this nice human readable output:

Link: https://lore.kernel.org/kdevops/aMnm2GQ0hdxNgYGd@bombadil.infradead.org/ [1]

make status
PLAY: MANAGE INFRASTRUCTURE LIFECYCLE AND SSH ACCESS WITH LIBVIRT/GUESTFS
TASK: Gathering Facts
start: [localhost]
start: [debian13-xarray]
ok: [localhost]
ok: [debian13-xarray]
TASK: Display VM status
start: [localhost]
 Id   Name              State
---------------------------------
 9    debian13-xarray   running
PLAYBOOK SUMMARY
================
STATUS        OK  CHANGED  FAILED  HOST
OK             1        0       0  debian13-xarray
OK             2        0       0  localhost

I think DIY should be the default stdout callback for kdevops. This
example is meant to encourage users to try it out, and if the feedback
is positive, we can move forward with a formal proposal (there's no
rush).
---
 kconfigs/Kconfig.libvirt                      | 1 +
 playbooks/roles/guestfs/tasks/main.yml        | 7 +++++++
 playbooks/roles/guestfs/tasks/status/main.yml | 9 +++++++++
 scripts/guestfs.Makefile                      | 5 ++++-
 scripts/status_guestfs.sh                     | 5 -----
 5 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/kconfigs/Kconfig.libvirt b/kconfigs/Kconfig.libvirt
index 25cb703f..af34a33c 100644
--- a/kconfigs/Kconfig.libvirt
+++ b/kconfigs/Kconfig.libvirt
@@ -118,6 +118,7 @@ endchoice
 
 config LIBVIRT_URI_PATH
 	string "Libvirt QEMU URI to use"
+	output yaml
 	default "qemu:///system" if LIBVIRT_URI_SYSTEM || LIBVIRT_URI_CUSTOM
 	default "qemu:///session" if LIBVIRT_URI_SESSION
 	help
diff --git a/playbooks/roles/guestfs/tasks/main.yml b/playbooks/roles/guestfs/tasks/main.yml
index 2ec44204..6618687e 100644
--- a/playbooks/roles/guestfs/tasks/main.yml
+++ b/playbooks/roles/guestfs/tasks/main.yml
@@ -77,3 +77,10 @@
   ansible.builtin.import_tasks:
     file: "{{ role_path }}/tasks/destroy.yml"
   delegate_to: localhost
+
+- name: Status VM tasks
+  tags:
+    - status
+  ansible.builtin.import_tasks:
+    file: "{{ role_path }}/tasks/status/main.yml"
+  delegate_to: localhost
diff --git a/playbooks/roles/guestfs/tasks/status/main.yml b/playbooks/roles/guestfs/tasks/status/main.yml
new file mode 100644
index 00000000..ad1e0348
--- /dev/null
+++ b/playbooks/roles/guestfs/tasks/status/main.yml
@@ -0,0 +1,9 @@
+---
+- name: Display VM status
+  ansible.builtin.shell: |
+    LIBVIRT_DEFAULT_URI="{{ libvirt_uri }}" virsh list --all
+  changed_when: false
+  delegate_to: localhost
+  run_once: true
+  vars:
+    ansible_callback_diy_runner_on_ok_msg: "{{ ansible_callback_diy.result.output.stdout }}"
diff --git a/scripts/guestfs.Makefile b/scripts/guestfs.Makefile
index 953c6149..68aa282f 100644
--- a/scripts/guestfs.Makefile
+++ b/scripts/guestfs.Makefile
@@ -91,7 +91,10 @@ bringup_guestfs: $(GUESTFS_BRINGUP_DEPS)
 PHONY += bringup_guestfs
 
 status_guestfs:
-	$(Q)scripts/status_guestfs.sh
+	$(Q)ansible-playbook $(ANSIBLE_VERBOSE) \
+		playbooks/guestfs.yml \
+		--extra-vars=@./extra_vars.yaml \
+		--tags status
 PHONY += status_guestfs
 
 destroy_guestfs:
diff --git a/scripts/status_guestfs.sh b/scripts/status_guestfs.sh
deleted file mode 100755
index 84cb26cf..00000000
--- a/scripts/status_guestfs.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-# SPDX-License-Identifier: copyleft-next-0.3.1
-
-virsh list
-exit 0

---
base-commit: 4deb164b5926aaef3f864f3a49358ec6c1da8238
change-id: 20250917-status-script-e22d4ac7b009

Best regards,
--  
Daniel Gomez <da.gomez@samsung.com>


             reply	other threads:[~2025-09-17  8:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-17  8:49 Daniel Gomez [this message]
2025-09-17 13:45 ` [PATCH] guestfs: port status script to Ansible with libvirt URI fix Chuck Lever
2025-09-17 14:28 ` 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=20250917-status-script-v1-1-4a792f9ca518@samsung.com \
    --to=da.gomez@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=da.gomez@samsung.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