From 88fbb6f629e59a15f65c5d0714d6174b11ea6553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Petazzoni?= Date: Wed, 20 Nov 2024 02:18:59 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=AD=20Store=20log/pass=20information?= =?UTF-8?q?=20in=20logins.jsonl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prepare-labs/lib/commands.sh | 28 +++++++++++-------- .../terraform/many-kubernetes/stage2.tmpl | 15 +++++----- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/prepare-labs/lib/commands.sh b/prepare-labs/lib/commands.sh index a3ddc709..50811da9 100644 --- a/prepare-labs/lib/commands.sh +++ b/prepare-labs/lib/commands.sh @@ -19,12 +19,14 @@ _cmd_cards() { TAG=$1 need_tag - die FIXME + OPTIONS_FILE=$2 + [ -f "$OPTIONS_FILE" ] || die "Please specify a YAML options file as 2nd argument." + OPTIONS_FILE_PATH="$(readlink -f "$OPTIONS_FILE")" - # This will process login.tsv to generate two files: cards.pdf and cards.html + # This will process logins.jsonl to generate two files: cards.pdf and cards.html ( cd tags/$TAG - ../../../lib/make-login-cards.py settings.yaml + ../../../lib/make-login-cards.py "$OPTIONS_FILE_PATH" ) ln -sf ../tags/$TAG/cards.html www/$TAG.html @@ -349,8 +351,8 @@ _cmd_clusterize() { " while read line; do - printf "%s\tssh -l %s\t%s\n" "$USER_PASSWORD" "$USER_LOGIN" "$line" - done < tags/$TAG/clusters.tsv > tags/$TAG/login.tsv + printf '{"login": "%s", "password": "%s", "ipaddrs": "%s"}\n' "$USER_LOGIN" "$USER_PASSWORD" "$line" + done < tags/$TAG/clusters.tsv > tags/$TAG/logins.jsonl echo cluster_ok > tags/$TAG/status } @@ -940,12 +942,13 @@ _cmd_inventory() { FIXME } -_cmd login "Show login information for a group of instances" -_cmd_login() { +_cmd logins "Show login information for a group of instances" +_cmd_logins() { TAG=$1 need_tag $TAG - cat tags/$TAG/login.tsv + cat tags/$TAG/logins.jsonl \ + | jq -r '"\(.password)\tssh -l \(.login)\(if .port then " -p \(.port)" else "" end)\t\(.ipaddrs)"' } _cmd maketag "Generate a quasi-unique tag for a group of instances" @@ -998,8 +1001,9 @@ _cmd_stage2() { cd tags/$TAG/stage2 terraform init -upgrade terraform apply -auto-approve - terraform output -raw login_tsv > ../login.tsv + terraform output -raw logins_jsonl > ../logins.jsonl terraform output -raw ips_txt > ../ips.txt + echo "stage2_ok" > status } _cmd standardize "Deal with non-standard Ubuntu cloud images" @@ -1179,8 +1183,8 @@ _cmd_tags() { cd tags echo "[#] [Status] [Tag] [Mode] [Provider]" for tag in *; do - if [ -f $tag/login.tsv ]; then - count="$(wc -l < $tag/login.tsv)" + if [ -f $tag/logins.jsonl ]; then + count="$(wc -l < $tag/logins.jsonl)" else count="?" fi @@ -1343,7 +1347,7 @@ EOF" _cmd www "Run a web server to access card HTML and PDF" _cmd_www() { cd www - IPADDR=$(curl -sL canihazip.com/s) + IPADDR=$(curl -fsSL canihazip.com/s || echo localhost) info "The following files are available:" for F in *; do echo "http://$IPADDR:8000/$F" diff --git a/prepare-labs/terraform/many-kubernetes/stage2.tmpl b/prepare-labs/terraform/many-kubernetes/stage2.tmpl index 10dbe923..0381d3b4 100644 --- a/prepare-labs/terraform/many-kubernetes/stage2.tmpl +++ b/prepare-labs/terraform/many-kubernetes/stage2.tmpl @@ -228,16 +228,15 @@ output "ips_txt" { ]) } -output "login_tsv" { +output "logins_jsonl" { value = join("\n", [ %{ for index, cluster in clusters ~} - join("\t", concat( - [ - random_string.shpod_${index}.result, - "ssh -l k8s -p $${kubernetes_service.shpod_${index}.spec[0].port[0].node_port}" - ], - split(" ", file("./externalips.${index}")) - )), + jsonencode({ + login = "k8s", + password = random_string.shpod_${index}.result, + port = kubernetes_service.shpod_${index}.spec[0].port[0].node_port, + ipaddrs = replace(file("./externalips.${index}"), " ", "\t"), + }), %{ endfor ~} "" ])