From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 42C5F24B26 for ; Mon, 28 Jul 2025 00:18:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753661886; cv=none; b=j0i31U/Yniw0piwdwyJqQHd5yYowLHQhUZpvoh6fKH6i5c6IZiP0+NTWfPToPZaZhjvITmPxTydbLwNShMjWfrbGPyQcwIqg2ngeV87Mt6QGHCdbINWWu9MqK3QlS7YeP17VSX4Q3gkWZIiFA+IW+781aGD7AGLjlsodsO0E4WQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753661886; c=relaxed/simple; bh=CWiLTnyknZXjC5y3dpxd/Dl3LGJxTKjc8VtMRLzpjJA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=icuDkSIz2YfVEgqULGnw+fLdzcuPO5yEwxFKOseJFFHVigU1xLwVAIHJ3Ia/UYRbzGYto+TH7/Ppi1VsRS4/uzQaRsBvo8Q/bzFdi7b28o2WflXKPhMIPU74YX2b6AR1g5HgxNawLzHme3jr1QGBXqW2cn1XPhdsh/fSaSaumvU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=4uTbeiw0; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="4uTbeiw0" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=zLERKrdIRpB7Phthhj6XTWzM4FacnRqUE1tTEdluVQA=; b=4uTbeiw0DVX6HNgrCDttsUCe73 8FZkfXzqYEuVwRdHjJTqvTg71dsIEXeuBF9d7mdWSzKuoWPUkM0mu6U14XCHgzUo+o1T8WUoUkEfL 4F6JbyssnoPXu8Bwq9OjqdbLzjzlWNhAa1FocWcV35ggWKKDKILHljspUJkI83IG8LXR/SNwwkaa0 PYYHt8hOr+mcBxM9a7rDG7RZyczvY2ldU5YwxAH+J79ek8J/D3pVK8Qt66Mdjjc7KNpetg7PT2td5 QXvB0DBkoZfgO0AZ/hJfCm4VXWLsuw2EMtm9IeDKZ0kIyKB/kTopNS1gq7i+/b2TLnFkVVCRP+EH1 WpnTSEsw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1ugBZ4-0000000DNWO-1pMd; Mon, 28 Jul 2025 00:18:02 +0000 From: Luis Chamberlain To: Chuck Lever , Daniel Gomez , kdevops@lists.linux.dev Cc: Chuck Lever Subject: [PATCH 16/40] terraform: Replace scripts/status_terraform.sh Date: Sun, 27 Jul 2025 17:17:35 -0700 Message-ID: <20250728001800.3188617-17-mcgrof@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250728001800.3188617-1-mcgrof@kernel.org> References: <20250728001800.3188617-1-mcgrof@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 Sender: Luis Chamberlain From: Chuck Lever Move the functionality into the terraform playbook so it can use the cloud.terraform.terraform module. Signed-off-by: Chuck Lever --- playbooks/roles/terraform/tasks/main.yml | 31 ++++++++++++++++++++++++ scripts/status_terraform.sh | 17 ------------- scripts/terraform.Makefile | 5 +++- 3 files changed, 35 insertions(+), 18 deletions(-) delete mode 100755 scripts/status_terraform.sh diff --git a/playbooks/roles/terraform/tasks/main.yml b/playbooks/roles/terraform/tasks/main.yml index b7ae0f0a..a64c93c6 100644 --- a/playbooks/roles/terraform/tasks/main.yml +++ b/playbooks/roles/terraform/tasks/main.yml @@ -39,6 +39,37 @@ tags: - ssh +- name: Report terraform status + tags: + - status + block: + - name: Retrieve the controller_ip_map from terraform + cloud.terraform.terraform_output: + format: json + name: controller_ip_map + project_path: "{{ topdir_path }}/terraform/{{ kdevops_terraform_provider }}" + register: terraform_output + + - name: End play -- terraform state file is empty or missing + ansible.builtin.meta: end_play + when: + - terraform_output.warnings is defined + + - name: Count active resources + ansible.builtin.command: + cmd: "terraform state list" + chdir: "{{ topdir_path }}/terraform/{{ kdevops_terraform_provider }}" + register: terraform_state + changed_when: false + + - name: Show status + ansible.builtin.debug: + msg: "Active resources: {{ terraform_state.stdout_lines | length }}" + + - name: Show controller IP map + ansible.builtin.debug: + var: terraform_output.value + - name: Remove the ephemeral ssh config file on the control host ansible.builtin.file: path: "{{ kdevops_ssh_config }}" diff --git a/scripts/status_terraform.sh b/scripts/status_terraform.sh deleted file mode 100755 index 9b016498..00000000 --- a/scripts/status_terraform.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: copyleft-next-0.3.1 - -[ -z "${TOPDIR}" ] && TOPDIR='.' -source ${TOPDIR}/.config -source ${TOPDIR}/scripts/lib.sh - -cd ${TOPDIR}/terraform/$1 -terraform refresh > /dev/null -COUNT=`terraform state list | wc -l` -if [[ ${COUNT} -eq 1 ]]; then - echo "There is 1 active terraform resource on '$1'." -else - echo "There are ${COUNT} active terraform resources on '$1'." -fi -terraform output controller_ip_map -exit 0 diff --git a/scripts/terraform.Makefile b/scripts/terraform.Makefile index adfd359c..09aafdc1 100644 --- a/scripts/terraform.Makefile +++ b/scripts/terraform.Makefile @@ -114,7 +114,10 @@ $(KDEVOPS_PROVISIONED_SSH): $(Q)touch $(KDEVOPS_PROVISIONED_SSH) status_terraform: - $(Q)scripts/status_terraform.sh $(KDEVOPS_CLOUD_PROVIDER) + $(Q)ansible-playbook $(ANSIBLE_VERBOSE) \ + --inventory localhost, \ + playbooks/terraform.yml --tags status \ + --extra-vars=@./extra_vars.yaml destroy_terraform: $(Q)ansible-playbook $(ANSIBLE_VERBOSE) \ -- 2.47.2