Skip to contentSkip to conversation

guestfs: port status script to Ansible with libvirt URI fix

PATCH Applied Daniel Gomez 3 participants 3 messages Sep 17, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 guestfs: port status script to Ansible with libvirt URI fix

From: Daniel Gomez <[email protected]>

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

---
The conversion in combination with the DIY stdout callback support [1] results in this nice human readable output:

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(-)
kconfigs/Kconfig.libvirt +1 -0
index 25cb703f..af34a33c 100644
@@ -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
playbooks/roles/guestfs/tasks/main.yml +7 -0
index 2ec44204..6618687e 100644
@@ -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
playbooks/roles/guestfs/tasks/status/main.yml new file +9 -0
new file mode 100644
index 00000000..ad1e0348
@@ -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 }}"
scripts/guestfs.Makefile +4 -1
index 953c6149..68aa282f 100644
@@ -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:
scripts/status_guestfs.sh deleted +0 -5
deleted file mode 100755
index 84cb26cf..00000000
@@ -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,

Signature · 1 line
Daniel Gomez <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Daniel Gomez

From: Daniel Gomez <[email protected]>

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

Quoted 6 lines

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

I hadn't done this already because the Ansible implementation of these steps takes noticeably more time. But I don't mind that if you guys don't.

Signature · 1 line
Chuck Lever
#2 lore raw
In reply to Daniel Gomez
Quoted 10 lines · Daniel Gomez

From: Daniel Gomez <[email protected]>

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

Quoted 6 lines

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

Thanks! Applied and pushed!

Luis