From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6078E28AAF9 for ; Thu, 22 May 2025 13:31:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747920700; cv=none; b=PSzJmAyhfxMr1URTtAFgce+CrXBcdjMnu6AScq9HuQyF5n/1BjYdhov923D0rm+lGbPXQiC+CVp4z2QcAH7Olq9LGrh7JwcfT66J+hN7wwGWI3V9QWY507E2oEApFPJF2yueW8VYk9RtbL/JtwADN13Mf63L9jdP/19dICEm22g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747920700; c=relaxed/simple; bh=8ilWWaRcLPn+xKPmWjcYxvJFDF18GwG8cxw+WO9o2do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fP8jJOFul62KYfKtO+aQJMj6AHz82aDqFRd+u20rRcjUK8TvsAoEbOvFcFdbTDE/+IaZORSOeUgpNrOXqhdfQc7WsbSeVrvCZi4+ewrUOIi8ZP1F1J3cyajCM5YUK1Ewm0ZKrVUrdgYQKkrTtWcCctejzi3zTjg7xbJ0XiAWZDc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P9/2qfq+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="P9/2qfq+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09C7EC4CEED; Thu, 22 May 2025 13:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747920700; bh=8ilWWaRcLPn+xKPmWjcYxvJFDF18GwG8cxw+WO9o2do=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P9/2qfq+HiRai2Tx1O0Wd7El8A6rn53ZCmUTt7rzh7AS6yCXbaUan4UuoSXJK4mY9 lA4tf7dc/uhjqO/8VFIjTlA7W3TRj4rHZgPHd8ZVZDefi+Xmt9GtdLcxda6XrI0Zsl Am148RS3OEY045yknxlCc0tWsxAxYqs3xq33pFw2a6C5aP5AO7h1u9Fm66nbb+7bjO YehznDhLBhi2XMJIplHMQl3HEa1mGThSZhX2d8azDQZJgSWCivxkKPsSQKST1Cn9Xt 5cHgYbYLhgpJxP0ykd4LlaDreQDjm7ReniolQ1/yeQ4AvsUw5EG3f/hsATpolQtrPO A4Vl71hn794bw== From: cel@kernel.org To: Cc: Chuck Lever Subject: [RFC PATCH 1/5] guestfs: Replace scripts/destroy_guestfs.sh with an Ansible playbook Date: Thu, 22 May 2025 09:31:33 -0400 Message-ID: <20250522133137.989457-2-cel@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250522133137.989457-1-cel@kernel.org> References: <20250522133137.989457-1-cel@kernel.org> Precedence: bulk X-Mailing-List: kdevops@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chuck Lever 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. Signed-off-by: Chuck Lever --- .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 diff --git a/.gitignore b/.gitignore index f51213a59ad9..0e3998485a36 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/destroy_guestfs.sh b/scripts/destroy_guestfs.sh deleted file mode 100755 index dfbb4f15f4ca..000000000000 --- a/scripts/destroy_guestfs.sh +++ /dev/null @@ -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 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