Skip to contentSkip to conversation

Convert bringup_guestfs to a single Ansible role

RFC PATCH Superseded [email protected] 2 participants 15 messages May 22, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Convert bringup_guestfs to a single Ansible role

From: Chuck Lever <[email protected]>

I dusted these off and rebased them on the current kdevops HEAD to demonstrate some of my thinking about how libvirt/guestfs bring-up might be expressed entirely using Ansible (ie with a minimal use of shell scripts).

These are still rough, and a role to deal with constructing base images is missing for now.

Chuck Lever (5):
guestfs: Replace scripts/destroy_guestfs.sh with an Ansible playbook Move the guestfs install-deps to the guestfs playbook
guestfs: Move console-related steps to guestfs role
guestfs: Move check-config, network, and storage-pool tags
guestfs: Convert part of scripts/bringup_guestfs.sh to Ansible

 .gitignore                                    |   1 +
 playbooks/guestfs.yml                         |   7 +
 playbooks/roles/guestfs/defaults/main.yml     |   5 +
 playbooks/roles/guestfs/tasks/bringup.yml     | 157 ++++++++++++++++++
 .../roles/guestfs/tasks/config-check.yml      |  34 ++++
 .../guestfs/tasks/console-permissions.yml     |  31 ++++
 playbooks/roles/guestfs/tasks/destroy.yml     |  32 ++++
 playbooks/roles/guestfs/tasks/extra_disks.yml |  16 ++
 .../tasks/install-deps/debian/main.yml        |  10 ++
 .../roles/guestfs/tasks/install-deps/main.yml |  21 +++
 .../tasks/install-deps/redhat/main.yml        |  12 ++
 .../guestfs/tasks/install-deps/suse/main.yml  |   9 +
 playbooks/roles/guestfs/tasks/largeio.yml     |  11 ++
 playbooks/roles/guestfs/tasks/main.yml        |  44 +++++
 playbooks/roles/guestfs/tasks/network.yml     |  83 +++++++++
 .../roles/guestfs/tasks/storage-pool-path.yml |  77 +++++++++
 scripts/bringup_guestfs.sh                    |  76 +--------
 scripts/destroy_guestfs.sh                    |  36 ----
 scripts/guestfs.Makefile                      |  23 ++-
 19 files changed, 566 insertions(+), 119 deletions(-)
 create mode 100644 playbooks/guestfs.yml
 create mode 100644 playbooks/roles/guestfs/defaults/main.yml
 create mode 100644 playbooks/roles/guestfs/tasks/bringup.yml
 create mode 100644 playbooks/roles/guestfs/tasks/config-check.yml
 create mode 100644 playbooks/roles/guestfs/tasks/console-permissions.yml
 create mode 100644 playbooks/roles/guestfs/tasks/destroy.yml
 create mode 100644 playbooks/roles/guestfs/tasks/extra_disks.yml
 create mode 100644 playbooks/roles/guestfs/tasks/install-deps/debian/main.yml
 create mode 100644 playbooks/roles/guestfs/tasks/install-deps/main.yml
 create mode 100644 playbooks/roles/guestfs/tasks/install-deps/redhat/main.yml
 create mode 100644 playbooks/roles/guestfs/tasks/install-deps/suse/main.yml
 create mode 100644 playbooks/roles/guestfs/tasks/largeio.yml
 create mode 100644 playbooks/roles/guestfs/tasks/main.yml
 create mode 100644 playbooks/roles/guestfs/tasks/network.yml
 create mode 100644 playbooks/roles/guestfs/tasks/storage-pool-path.yml
 delete mode 100755 scripts/destroy_guestfs.sh
Signature · 1 line
2.49.0
#1 lore raw

RFC PATCH 1/5 guestfs: Replace scripts/destroy_guestfs.sh with an Ansible playbook

From: Chuck Lever <[email protected]>

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.

---
 .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
.gitignore +1 -0
index f51213a59ad9..0e3998485a36 100644
@@ -6,6 +6,7 @@
 .provisioned_once*
 
 guestfs/
+!playbooks/roles/guestfs/
 
 linux/
 !workflows/linux/
playbooks/guestfs.yml new file +7 -0
new file mode 100644
index 000000000000..8bb496e0f05a
@@ -0,0 +1,7 @@
+---
+- name: Provision target nodes with libvirt/guestfs
+  gather_facts: false
+  connection: local
+  hosts: all
+  roles:
+    - role: guestfs
playbooks/roles/guestfs/tasks/destroy.yml new file +32 -0
new file mode 100644
index 000000000000..e26aacde4cff
@@ -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 }}"
playbooks/roles/guestfs/tasks/main.yml new file +6 -0
new file mode 100644
index 000000000000..60d4ffd40a20
@@ -0,0 +1,6 @@
+---
+- name: Shut down and destroy each target node
+  tags:
+    - destroy
+  ansible.builtin.import_tasks:
+    file: "{{ role_path }}/tasks/destroy.yml"
scripts/destroy_guestfs.sh deleted +0 -36
deleted file mode 100755
index dfbb4f15f4ca..000000000000
@@ -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
scripts/guestfs.Makefile +4 -2
index 8d4aac3e3669..5d355ec70f8c 100644
@@ -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:
Signature · 1 line
2.49.0
Reviewed-by on v1 1/5
#2 lore raw

Re: [RFC PATCH 1/5] guestfs: Replace scripts/destroy_guestfs.sh with an Ansible playbook

Quoted 8 lines · On Thu, May 22, 2025 at 09:31:33AM -0400, [email protected] wrote:

From: Chuck Lever <[email protected]>

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.

+- name: Remove per-node configuration files

playbooks/roles/guestfs/tasks/destroy.yml line 23

Quoted 6 lines
playbooks/roles/guestfs/tasks/destroy.yml new file +6 -0
+  ansible.builtin.file:
+    path: "{{ item }}"
+    state: absent
+  loop:
+    - "{{ guestfs_path }}/{{ inventory_hostname }}"
+    - "{{ kdevops_storage_pool_path }}/guestfs/{{ inventory_hostname }}"

Does this remove a directory? If so then:

Luis

#3 lore raw

Re: [RFC PATCH 1/5] guestfs: Replace scripts/destroy_guestfs.sh with an Ansible playbook

Quoted 16 lines · Luis Chamberlain
Quoted 8 lines · On Thu, May 22, 2025 at 09:31:33AM -0400, [email protected] wrote:

From: Chuck Lever <[email protected]>

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.

+- name: Remove per-node configuration files

playbooks/roles/guestfs/tasks/destroy.yml line 23

Quoted 6 lines
playbooks/roles/guestfs/tasks/destroy.yml new file +6 -0
+  ansible.builtin.file:
+    path: "{{ item }}"
+    state: absent
+  loop:
+    - "{{ guestfs_path }}/{{ inventory_hostname }}"
+    - "{{ kdevops_storage_pool_path }}/guestfs/{{ inventory_hostname }}"
Quoted 5 lines

Does this remove a directory? If so then:

Luis

I think it does remove directories: guestfs/ is empty after these steps complete.

Signature · 1 line
Chuck Lever
#4 lore raw

RFC PATCH 2/5 Move the guestfs install-deps to the guestfs playbook

In reply to [email protected]

From: Chuck Lever <[email protected]>

In addition to copying the install-deps scripts, switch to using import_tasks, which has more dependable behavior and avoids the need to add a "tags:" keyword on each step.

---
 .../tasks/install-deps/debian/main.yml        | 10 +++++++++
 .../roles/guestfs/tasks/install-deps/main.yml | 21 +++++++++++++++++++
 .../tasks/install-deps/redhat/main.yml        | 12 +++++++++++
 .../guestfs/tasks/install-deps/suse/main.yml  |  9 ++++++++
 playbooks/roles/guestfs/tasks/main.yml        |  6 ++++++
 scripts/guestfs.Makefile                      |  4 ++--
 6 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 playbooks/roles/guestfs/tasks/install-deps/debian/main.yml
 create mode 100644 playbooks/roles/guestfs/tasks/install-deps/main.yml
 create mode 100644 playbooks/roles/guestfs/tasks/install-deps/redhat/main.yml
 create mode 100644 playbooks/roles/guestfs/tasks/install-deps/suse/main.yml
playbooks/roles/guestfs/tasks/install-deps/debian/main.yml new file +10 -0
new file mode 100644
index 000000000000..5935f752a493
@@ -0,0 +1,10 @@
+---
+- name: Install guestfs dependencies for Debian
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.package:
+    update_cache: true
+    name:
+      - libguestfs-tools
+      - isc-dhcp-client
+    state: present
playbooks/roles/guestfs/tasks/install-deps/main.yml new file +21 -0
new file mode 100644
index 000000000000..5cbc55dcb188
@@ -0,0 +1,21 @@
+---
+- name: Gathering facts
+  ansible.builtin.gather_facts:
+
+- name: Debian-specific setup
+  ansible.builtin.import_tasks:
+    file: debian/main.yml
+  when:
+    - ansible_os_family == "Debian"
+
+- name: SuSE-specific setup
+  ansible.builtin.import_tasks:
+    file: suse/main.yml
+  when:
+    - ansible_os_family == "Suse"
+
+- name: Red Hat-specific setup
+  ansible.builtin.import_tasks:
+    file: redhat/main.yml
+  when:
+    - ansible_os_family == "Redhat"
playbooks/roles/guestfs/tasks/install-deps/redhat/main.yml new file +12 -0
new file mode 100644
index 000000000000..c28a16a07c7a
@@ -0,0 +1,12 @@
+---
+- name: Install guestfs dependencies for Red Hat Enterprise
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.package:
+    update_cache: true
+    name:
+      - libguestfs-tools
+      - dhcpcd
+    state: present
+  when:
+    - ansible_distribution != "Fedora"
playbooks/roles/guestfs/tasks/install-deps/suse/main.yml new file +9 -0
new file mode 100644
index 000000000000..c1bf24354612
@@ -0,0 +1,9 @@
+---
+- name: Install guestfs dependencies for Suse
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.package:
+    name:
+      - libguestfs-tools
+      - dhcpcd
+    state: present
playbooks/roles/guestfs/tasks/main.yml +6 -0
index 60d4ffd40a20..ba38a67c4baf 100644
@@ -1,4 +1,10 @@
 ---
+- name: Install guestfs dependencies on the Ansible controller
+  tags:
+    - install-deps
+  ansible.builtin.import_tasks:
+    file: "{{role_path }}/tasks/install-deps/main.yml"
+
 - name: Shut down and destroy each target node
   tags:
     - destroy
scripts/guestfs.Makefile +2 -2
index 5d355ec70f8c..4ad347544cf6 100644
@@ -68,9 +68,9 @@ $(KDEVOPS_PROVISIONED_SSH):
 	$(Q)touch $(KDEVOPS_PROVISIONED_SSH)
 
 install_libguestfs:
-	$(Q)ansible-playbook $(ANSIBLE_VERBOSE) --connection=local \
+	$(Q)ansible-playbook $(ANSIBLE_VERBOSE) \
 		--inventory localhost, \
-		playbooks/bringup_guestfs.yml \
+		playbooks/guestfs.yml \
 		--extra-vars=@./extra_vars.yaml \
 		--tags install-deps
 
Signature · 1 line
2.49.0
Reviewed-by on v1 2/5
#5 lore raw

Re: [RFC PATCH 2/5] Move the guestfs install-deps to the guestfs playbook

Quoted 33 lines · On Thu, May 22, 2025 at 09:31:34AM -0400, [email protected] wrote:

From: Chuck Lever <[email protected]>

In addition to copying the install-deps scripts, switch to using import_tasks, which has more dependable behavior and avoids the need to add a "tags:" keyword on each step.

playbooks/roles/guestfs/tasks/install-deps/debian/main.yml +8 -0
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.package:
+    update_cache: true
+    name:
+      - libguestfs-tools
+      - isc-dhcp-client
+    state: present
playbooks/roles/guestfs/tasks/install-deps/main.yml +11 -0
+++ b/playbooks/roles/guestfs/tasks/install-deps/redhat/main.yml
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.package:
+    update_cache: true
+    name:
+      - libguestfs-tools
+      - dhcpcd
+    state: present
+  when:
+    - ansible_distribution != "Fedora"
playbooks/roles/guestfs/tasks/install-deps/suse/main.yml new file +0 -0
new file mode 100644
index 000000000000..c1bf24354612

playbooks/roles/guestfs/tasks/install-deps/suse/main.yml

Quoted 7 lines
playbooks/roles/guestfs/tasks/install-deps/suse/main.yml new file +7 -0
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.package:
+    name:
+      - libguestfs-tools
+      - dhcpcd
+    state: present

If you use the pkg role then we'd just need to add a definition overide for dhcpd for debian as isc-dhcp-client and we'd have one shared install step here.

Otherwise:

Luis

#6 lore raw

Re: [RFC PATCH 2/5] Move the guestfs install-deps to the guestfs playbook

Quoted 37 lines · Luis Chamberlain
Quoted 36 lines · On Thu, May 22, 2025 at 09:31:34AM -0400, [email protected] wrote:

From: Chuck Lever <[email protected]>

In addition to copying the install-deps scripts, switch to using import_tasks, which has more dependable behavior and avoids the need to add a "tags:" keyword on each step.

playbooks/roles/guestfs/tasks/install-deps/debian/main.yml +8 -0
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.package:
+    update_cache: true
+    name:
+      - libguestfs-tools
+      - isc-dhcp-client
+    state: present
playbooks/roles/guestfs/tasks/install-deps/main.yml +11 -0
+++ b/playbooks/roles/guestfs/tasks/install-deps/redhat/main.yml
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.package:
+    update_cache: true
+    name:
+      - libguestfs-tools
+      - dhcpcd
+    state: present
+  when:
+    - ansible_distribution != "Fedora"
playbooks/roles/guestfs/tasks/install-deps/suse/main.yml new file +3 -0
new file mode 100644
index 000000000000..c1bf24354612
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.builtin.package:
Quoted 8 lines

playbooks/roles/guestfs/tasks/install-deps/suse/main.yml

Quoted 4 lines
playbooks/roles/guestfs/tasks/install-deps/suse/main.yml new file +4 -0
+    name:
+      - libguestfs-tools
+      - dhcpcd
+    state: present

If you use the pkg role then we'd just need to add a definition overide for dhcpd for debian as isc-dhcp-client and we'd have one shared install step here.

Almost true. Check redhat/main.yml -- there is a little extra logic there.

Also, I've done that kind of de-duplication in the past, and half the time I end up undo-ing it because more logic is needed at a later point.

Thinking ahead (always dangerous).

Quoted 5 lines

Otherwise:

Luis

Signature · 1 line
Chuck Lever
#7 lore raw

Re: [RFC PATCH 2/5] Move the guestfs install-deps to the guestfs playbook

Quoted 2 lines · Chuck Lever

Almost true. Check redhat/main.yml -- there is a little extra logic there.

Ahhh.

Quoted 3 lines

Also, I've done that kind of de-duplication in the past, and half the time I end up undo-ing it because more logic is needed at a later point.

I see...

Quoted 1 line

Thinking ahead (always dangerous).

Good to know, ok so we'll need to live with this, and have to just take this up in the future with the ansible community long term.

Luis

#8 lore raw

RFC PATCH 3/5 guestfs: Move console-related steps to guestfs role

In reply to [email protected]

From: Chuck Lever <[email protected]>

These steps are relocated because my plan is to remove the bringup_guestfs role eventually.

---
 playbooks/roles/guestfs/defaults/main.yml     |  3 ++
 .../guestfs/tasks/console-permissions.yml     | 31 +++++++++++++++++++
 playbooks/roles/guestfs/tasks/main.yml        |  8 +++++
 scripts/guestfs.Makefile                      |  4 +--
 4 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 playbooks/roles/guestfs/defaults/main.yml
 create mode 100644 playbooks/roles/guestfs/tasks/console-permissions.yml
playbooks/roles/guestfs/defaults/main.yml new file +3 -0
new file mode 100644
index 000000000000..0d1e2ef82ae9
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier GPL-2.0+
+---
+libvirt_uri_system: false
playbooks/roles/guestfs/tasks/console-permissions.yml new file +31 -0
new file mode 100644
index 000000000000..ad169a4eab31
@@ -0,0 +1,31 @@
+---
+- name: Get the user who invoked Ansible
+  ansible.builtin.command:
+    cmd: whoami
+  register: reg_user
+  changed_when: false
+
+- name: Look for console.log files in guestfs subdirectories to check for CI enablement
+  become: true
+  become_flags: 'su - -c'
+  become_method: ansible.builtin.sudo
+  ansible.builtin.find:
+    paths: "{{ topdir_path }}/guestfs"
+    patterns: "console.log"
+    file_type: file
+    recurse: true
+  register: console_log_files
+
+- name: Ensure console.log files are owned by the main user for CI monitoring
+  become: true
+  become_flags: 'su - -c'
+  become_method: ansible.builtin.sudo
+  ansible.builtin.file:
+    path: "{{ item.path }}"
+    owner: "{{ reg_user.stdout }}"
+    group: "{{ reg_user.stdout }}"
+  loop: "{{ console_log_files.files }}"
+  loop_control:
+    label: "{{ item.path | regex_replace('^.*guestfs/', 'guestfs/') }}"
+  when:
+    - console_log_files.matched > 0
playbooks/roles/guestfs/tasks/main.yml +8 -0
index ba38a67c4baf..a469d48a082b 100644
@@ -5,6 +5,14 @@
   ansible.builtin.import_tasks:
     file: "{{role_path }}/tasks/install-deps/main.yml"
 
+- name: Set up target node console permissions
+  tags:
+    - console-permissions
+  ansible.builtin.import_tasks:
+    file: "{{ role_path }}/tasks/console-permissions.yml"
+  when:
+    - libvirt_uri_system|bool
+
 - name: Shut down and destroy each target node
   tags:
     - destroy
scripts/guestfs.Makefile +2 -2
index 4ad347544cf6..30bef9d17e99 100644
@@ -81,9 +81,9 @@ bringup_guestfs: $(GUESTFS_BRINGUP_DEPS)
 		--extra-vars=@./extra_vars.yaml \
 		--tags config-check,network,storage-pool-path
 	$(Q)$(TOPDIR)/scripts/bringup_guestfs.sh
-	$(Q)ansible-playbook $(ANSIBLE_VERBOSE) --connection=local \
+	$(Q)ansible-playbook $(ANSIBLE_VERBOSE) \
 		--inventory localhost, \
-		playbooks/bringup_guestfs.yml \
+		playbooks/guestfs.yml \
 		--extra-vars=@./extra_vars.yaml \
 		--tags console-permissions
 PHONY += bringup_guestfs
Signature · 1 line
2.49.0
Reviewed-by on v1 3/5
#9 lore raw

Re: [RFC PATCH 3/5] guestfs: Move console-related steps to guestfs role

Quoted 6 lines · On Thu, May 22, 2025 at 09:31:35AM -0400, [email protected] wrote:

From: Chuck Lever <[email protected]>

These steps are relocated because my plan is to remove the bringup_guestfs role eventually.

For 4 and 5:

But just one nit-pick: it says move, but its not deleting the code it is moving.

LUis

#10 lore raw

Re: [RFC PATCH 3/5] guestfs: Move console-related steps to guestfs role

Quoted 8 lines · Luis Chamberlain
Quoted 6 lines · On Thu, May 22, 2025 at 09:31:35AM -0400, [email protected] wrote:

From: Chuck Lever <[email protected]>

These steps are relocated because my plan is to remove the bringup_guestfs role eventually.

Quoted 8 lines

For 4 and 5:

But just one nit-pick: it says move, but its not deleting the code it is moving.

LUis

I'm planning to include a patch at the end that removes the bringup_guestfs role. But fair enough, I will change the verb to "copy".

Signature · 1 line
Chuck Lever
#11 lore raw

Re: [RFC PATCH 3/5] guestfs: Move console-related steps to guestfs role

Quoted 14 lines · Chuck Lever
Quoted 13 lines · Luis Chamberlain
Quoted 6 lines · On Thu, May 22, 2025 at 09:31:35AM -0400, [email protected] wrote:

From: Chuck Lever <[email protected]>

These steps are relocated because my plan is to remove the bringup_guestfs role eventually.

For 4 and 5:

But just one nit-pick: it says move, but its not deleting the code it is moving.

Quoted 7 lines
Quoted 3 lines

LUis

I'm planning to include a patch at the end that removes the bringup_guestfs role. But fair enough, I will change the verb to "copy".

Fine by me, nuke nuke nuke!

Luis

#12 lore raw

RFC PATCH 4/5 guestfs: Move check-config, network, and storage-pool tags

In reply to [email protected]

From: Chuck Lever <[email protected]>

These steps are relocated because my plan is to remove the bringup_guestfs role eventually.

I'm not sure the config-check steps are absolutely necessary, but are retained for now.

---
 playbooks/roles/guestfs/defaults/main.yml     |  1 +
 .../roles/guestfs/tasks/config-check.yml      | 34 ++++++++
 playbooks/roles/guestfs/tasks/main.yml        | 18 ++++
 playbooks/roles/guestfs/tasks/network.yml     | 83 +++++++++++++++++++
 .../roles/guestfs/tasks/storage-pool-path.yml | 77 +++++++++++++++++
 scripts/guestfs.Makefile                      |  4 +-
 6 files changed, 215 insertions(+), 2 deletions(-)
 create mode 100644 playbooks/roles/guestfs/tasks/config-check.yml
 create mode 100644 playbooks/roles/guestfs/tasks/network.yml
 create mode 100644 playbooks/roles/guestfs/tasks/storage-pool-path.yml
playbooks/roles/guestfs/defaults/main.yml +1 -0
index 0d1e2ef82ae9..dc955d915d70 100644
@@ -1,3 +1,4 @@
 # SPDX-License-Identifier GPL-2.0+
 ---
 libvirt_uri_system: false
+distro_debian_based: false
playbooks/roles/guestfs/tasks/config-check.yml new file +34 -0
new file mode 100644
index 000000000000..e8cbb9b623a7
@@ -0,0 +1,34 @@
+---
+- name: Verify kdevops .config exists
+  ansible.builtin.stat:
+    path: "{{ topdir_path }}/.config"
+  register: config_file
+
+- name: Fail if kdevops .config is not present
+  ansible.builtin.fail:
+    msg: "kdevops is not confgured. You must run 'make menuconfig'"
+  when: not config_file.stat.exists or not config_file.stat.isreg
+
+- name: Check if guestfs directory exists
+  ansible.builtin.stat:
+    path: "{{ topdir_path }}/guestfs"
+  register: guestfs_dir_stat
+
+- name: Fail if guestfs directory does not exist
+  ansible.builtin.fail:
+    msg: "The guestfs directory does not exist. You must run make first."
+  when: not guestfs_dir_stat.stat.exists
+
+- name: Check for directories in guestfs/
+  ansible.builtin.find:
+    paths: "{{ topdir_path }}/guestfs"
+    file_type: directory
+    recurse: false
+    depth: 1
+  register: guestfs_subdirectories
+  when: guestfs_dir_stat.stat.exists
+
+- name: Fail if no directories found in guestfs/
+  ansible.builtin.fail:
+    msg: "No directories found in guestfs. You must run make first."
+  when: guestfs_subdirectories.matched == 0
playbooks/roles/guestfs/tasks/main.yml +18 -0
index a469d48a082b..bda91de79983 100644
@@ -5,6 +5,24 @@
   ansible.builtin.import_tasks:
     file: "{{role_path }}/tasks/install-deps/main.yml"
 
+- name: Check basic guestfs configuration
+  tags:
+    - config-check
+  ansible.builtin.import_tasks:
+    file: "{{role_path }}/tasks/config-check.yml"
+
+- name: Configure libvirt storage pool
+  tags:
+    - storage-pool-path
+  ansible.builtin.import_tasks:
+    file: "{{role_path }}/tasks/storage-pool-path.yml"
+
+- name: Configure libvirt networking
+  tags:
+    - network
+  ansible.builtin.import_tasks:
+    file: "{{role_path }}/tasks/network.yml"
+
 - name: Set up target node console permissions
   tags:
     - console-permissions
playbooks/roles/guestfs/tasks/network.yml new file +83 -0

83 lines not on this page · raw message

playbooks/roles/guestfs/tasks/storage-pool-path.yml new file +77 -0

77 lines not on this page · raw message

scripts/guestfs.Makefile +2 -2
index 30bef9d17e99..290315ee9c9e 100644
@@ -75,9 +75,9 @@ install_libguestfs:
 		--tags install-deps
 
 bringup_guestfs: $(GUESTFS_BRINGUP_DEPS)
-	$(Q)ansible-playbook $(ANSIBLE_VERBOSE) --connection=local \
+	$(Q)ansible-playbook $(ANSIBLE_VERBOSE) \
 		--inventory localhost, \
-		playbooks/bringup_guestfs.yml \
+		playbooks/guestfs.yml \
 		--extra-vars=@./extra_vars.yaml \
 		--tags config-check,network,storage-pool-path
 	$(Q)$(TOPDIR)/scripts/bringup_guestfs.sh
Signature · 1 line
2.49.0
#13 lore raw

RFC PATCH 5/5 guestfs: Convert part of scripts/bringup_guestfs.sh to Ansible

In reply to [email protected]

From: Chuck Lever <[email protected]>

The part of bringup_guestfs.sh that provisions and starts up target nodes is converted to Ansible. This parallelizes node bringup. The new Ansible code takes a stab at being more idempotent than the script was, as well.

The part of bringup_guestfs.sh that creates missing base images is left in place for the moment.

---
 playbooks/roles/guestfs/defaults/main.yml     |   1 +
 playbooks/roles/guestfs/tasks/bringup.yml     | 157 ++++++++++++++++++
 playbooks/roles/guestfs/tasks/extra_disks.yml |  16 ++
 playbooks/roles/guestfs/tasks/largeio.yml     |  11 ++
 playbooks/roles/guestfs/tasks/main.yml        |   6 +
 scripts/bringup_guestfs.sh                    |  76 +--------
 scripts/guestfs.Makefile                      |   5 +
 7 files changed, 197 insertions(+), 75 deletions(-)
 create mode 100644 playbooks/roles/guestfs/tasks/bringup.yml
 create mode 100644 playbooks/roles/guestfs/tasks/extra_disks.yml
 create mode 100644 playbooks/roles/guestfs/tasks/largeio.yml
playbooks/roles/guestfs/defaults/main.yml +1 -0
index dc955d915d70..448ff1f0c6c5 100644
@@ -2,3 +2,4 @@
 ---
 libvirt_uri_system: false
 distro_debian_based: false
+libvirt_enable_largeio: false
playbooks/roles/guestfs/tasks/bringup.yml new file +157 -0

157 lines not on this page · raw message

playbooks/roles/guestfs/tasks/extra_disks.yml new file +16 -0
new file mode 100644
index 000000000000..c8a9bd63885f
@@ -0,0 +1,16 @@
+---
+- name: Create the new drive image
+  ansible.builtin.command:
+    argv:
+      - "qemu-img"
+      - "create"
+      - "-f"
+      - "{{ libvirt_extra_drive_format }}"
+      - "{{ path }}"
+      - "100G"
+
+- name: Adjust the permission settings of the drive image file
+  ansible.builtin.file:
+    path: "{{ path }}"
+    group: "{{ libvirt_qemu_group }}"
+    mode: "g+rw,o-rw"
playbooks/roles/guestfs/tasks/largeio.yml new file +11 -0
new file mode 100644
index 000000000000..4246677d18d8
@@ -0,0 +1,11 @@
+---
+- name: Compute the total number of devices to build
+  ansible.builtin.set_fact:
+    total_devices: "{{ libvirt_largeio_pow_limit * libvirt_largeio_drives_per_space }}"
+
+- name: Create largeio block devices
+  ansible.builtin.include_tasks:
+    file: "{{ role_path }}/tasks/extra_disks.yml"
+  vars:
+    path: "{{ storagedir }}/{{ inventory_hostname }}/extra{{ item }}.{{ libvirt_extra_drive_format }}"
+  loop: "{{ range(0, total_devices) | list }}"
playbooks/roles/guestfs/tasks/main.yml +6 -0
index bda91de79983..e63484b0229d 100644
@@ -23,6 +23,12 @@
   ansible.builtin.import_tasks:
     file: "{{role_path }}/tasks/network.yml"
 
+- name: Bring up each target node
+  tags:
+    - bringup
+  ansible.builtin.import_tasks:
+    file: "{{role_path }}/tasks/bringup.yml"
+
 - name: Set up target node console permissions
   tags:
     - console-permissions
scripts/bringup_guestfs.sh +1 -75

79 lines not on this page · raw message

scripts/guestfs.Makefile +5 -0
index 290315ee9c9e..84cf99db982d 100644
@@ -81,6 +81,11 @@ bringup_guestfs: $(GUESTFS_BRINGUP_DEPS)
 		--extra-vars=@./extra_vars.yaml \
 		--tags config-check,network,storage-pool-path
 	$(Q)$(TOPDIR)/scripts/bringup_guestfs.sh
+	$(Q)ansible-playbook $(ANSIBLE_VERBOSE) \
+		-i hosts \
+		playbooks/guestfs.yml \
+		--extra-vars=@./extra_vars.yaml \
+		--tags bringup
 	$(Q)ansible-playbook $(ANSIBLE_VERBOSE) \
 		--inventory localhost, \
 		playbooks/guestfs.yml \
Signature · 1 line
2.49.0
Reviewed-by on v1 5/5
#14 lore raw

Re: [RFC PATCH 5/5] guestfs: Convert part of scripts/bringup_guestfs.sh to Ansible

Quoted 11 lines · On Thu, May 22, 2025 at 09:31:37AM -0400, [email protected] wrote:

From: Chuck Lever <[email protected]>

The part of bringup_guestfs.sh that provisions and starts up target nodes is converted to Ansible. This parallelizes node bringup. The new Ansible code takes a stab at being more idempotent than the script was, as well.

The part of bringup_guestfs.sh that creates missing base images is left in place for the moment.

Wow, just wow, thanks for all this.

Luis