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 B5D212367CB for ; Fri, 30 May 2025 17:52:33 +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=1748627553; cv=none; b=WX/aRGsT27YXIga1MPOsnUk8kFZuNOj8WQwuOmXiqnndmstnafN2XHnTqgCtTdjPKsa/HfbfVPB3IZ7oS0ZPYZFWMtq6qlWhfYOjtW8Y7ZK5Gr76I7oOKbQBOJObkOGlVZA9sNYSEUlxN01/yLy5REH4eOgyiL2dYsP634awBy4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748627553; c=relaxed/simple; bh=iAp6YCPCa073x1frmyUp+UBEPobn44uLzv25ZF5MdGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OmC6GjK4zZvGW5J6rTdavnOvrxoF1CjFAwO/dK1Sy3Bj0mKH3J+LE1f7KxWPEylBFD6Meh419JkolAyKctKIJO8oCASEsoY2hY1M2BDIU8wQTIxPSqK7rH7o5299WVsbWF6HW94QemR3CPLoAIKDf6FpePPpKOtLhfwdItMKlPY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ajbiiMPc; 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="ajbiiMPc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBFAEC4CEEB; Fri, 30 May 2025 17:52:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1748627553; bh=iAp6YCPCa073x1frmyUp+UBEPobn44uLzv25ZF5MdGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ajbiiMPcOQk5a07N9RdABlO95dDwE14b0r7Znr18JfBBvlv5o539A7JfNFOaIxRYs O80odYbfuoiKJQopkHmGFldpJKaX33YWKWmP44A6eJKPE/AFsop4d8Qd5TtFa9vGH5 DfCeJWQ2eBbNXV0w1qsWW+2iPSBbIPM2DKfYHgNXEuDG618Krqg+kWRuDiwqfMK+ro AbypUiX6iHO7sIDHWcBSw+RnmBXvsPOP9/jou4sp0+0RcFfdn4DifeRSQn9/Bje4K1 tHcHGuzk8RvqEAAPm5WHs2JoIgpnsHl2cx8A5oT+gXI8bKC7gyR+PlC0wwJ5eTiYtd hsX9wBh/X0/SA== From: Chuck Lever To: Cc: Chuck Lever , Luis Chamberlain Subject: [PATCH v2 01/12] guestfs: Replace scripts/destroy_guestfs.sh with an Ansible playbook Date: Fri, 30 May 2025 13:52:18 -0400 Message-ID: <20250530175229.489925-2-cel@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250530175229.489925-1-cel@kernel.org> References: <20250530175229.489925-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 Use Ansible for destroying libvirt-based target nodes. This replaces an open-coded loop over the target node hosts, and makes the destroy target more idempotent. Also, this change is a prerequisite to making guestfs and terraform manage their ssh key material in the same way, eventually. Reviewed-by: Luis Chamberlain 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/guestfs.Makefile | 6 +++-- 5 files changed, 50 insertions(+), 2 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 diff --git a/.gitignore b/.gitignore index 45113a669390..706ef3fca950 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/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