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 A1C111865EE for ; Mon, 28 Jul 2025 01:14:36 +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=1753665280; cv=none; b=oxDEautRLIbjrllE5HNl2X44bwf60cPT73fwqtEnMv1yANrm9bpWXI31V4h4pkCdJWsa9Rjjvarcdlvbrvfj1YB2pQq1oQb280Na4Sd4zsT5QXCNYmRCr25x2d6fHmpiPsBFyzVr9b5tznro6JELOZVNixhlFVe/IVdeZ3n+Xlw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753665280; c=relaxed/simple; bh=CWiLTnyknZXjC5y3dpxd/Dl3LGJxTKjc8VtMRLzpjJA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K3tR/5lhujzgJ1JKre1PyvsgTI324i1j+cPAVlB0CFgh7WeSok2A94TINGeecPQbDI0oArLGpeG1vMsoZIPVnrshC4uRjjckE4d+E9KRETBAQotnMYzhugfQg4x4qJ7ObHkd/d35cDll/QVNL2+c05zptv3DrXNyne5G6eUUIEU= 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=QQw0vt18; 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="QQw0vt18" 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=QQw0vt18xF/f3spvLIZGjr2hNU gLcDqa5emPR+mNhs4jQEJNXgEDrRy4cMMECtGhm4zvlCULAFRuwJbzFCX0leBccc7XhuVN7X7Dk0E WbOmMw5ruUVfwtvUOkuWOSH1WvcRbNKyCqd5VOKh7SR5b2dw+5ntY5CPorDHsXb8hZeRVrR/nQadz DLWKFwwJJKmK8SkP5KbZJd7hdRsxrXk4GSOw2o3nCUOT79rpB1L5yPiqtu6AkVDprMIDPK8WIOBkX 09eG8VUi0l2kWUGy2htyxd9TMeo0UuAqZxXpndQWnvWHPt3N535ezeWc+xYLsEafwvg/rhw8DAvCu 5VHGOZhg==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1ugCRn-0000000DPji-44cx; Mon, 28 Jul 2025 01:14:35 +0000 From: Luis Chamberlain To: Chuck Lever , Daniel Gomez , kdevops@lists.linux.dev Cc: Chuck Lever Subject: [PATCH v2 13/33] terraform: Replace scripts/status_terraform.sh Date: Sun, 27 Jul 2025 18:14:13 -0700 Message-ID: <20250728011434.3197091-14-mcgrof@kernel.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250728011434.3197091-1-mcgrof@kernel.org> References: <20250728011434.3197091-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