guestfs: port status script to Ansible with libvirt URI fix
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.
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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]>
Quoted 10 lines · Daniel Gomez
From: Daniel Gomez <[email protected]>
Convert
scripts/status_guestfs.shshell script to Ansible implementation inplaybooks/roles/guestfs/tasks/status/main.yml. The new implementation:- Uses proper
libvirt_urivariable forLIBVIRT_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.Makefileto call ansible-playbook with --tags status instead of the shell script. Add missing output yaml toLIBVIRT_URI_PATHfor proper URI variable generation.Generated-by Claude AISigned-off-by Daniel Gomez <[email protected]>
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
Luis Chamberlain
AppliedQuoted 10 lines · Daniel Gomez
From: Daniel Gomez <[email protected]>
Convert
scripts/status_guestfs.shshell script to Ansible implementation inplaybooks/roles/guestfs/tasks/status/main.yml. The new implementation:- Uses proper
libvirt_urivariable forLIBVIRT_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.Makefileto call ansible-playbook with --tags status instead of the shell script. Add missing output yaml toLIBVIRT_URI_PATHfor proper URI variable generation.Generated-by Claude AISigned-off-by Daniel Gomez <[email protected]>
Thanks! Applied and pushed!
Luis