aboutsummaryrefslogtreecommitdiff
path: root/terraform/ansible/inventory
diff options
context:
space:
mode:
Diffstat (limited to 'terraform/ansible/inventory')
-rwxr-xr-x[-rw-r--r--]terraform/ansible/inventory23
1 files changed, 21 insertions, 2 deletions
diff --git a/terraform/ansible/inventory b/terraform/ansible/inventory
index 95f5046..24bbc2e 100644..100755
--- a/terraform/ansible/inventory
+++ b/terraform/ansible/inventory
@@ -1,5 +1,24 @@
#!/bin/bash
-set -euo pipefail
+read -r -d '' script <<'EOF'
+to_entries|map({(.key|tostring):.value.value})|add as $input |
+
+$input.k8s_node_names|to_entries|map({(.value):{
+ ansible_host:$input.k8s_node_public_ips[.key],
+ private_ip:$input.k8s_node_private_ips[.key]}
+ }) as $nodes |
+
+{
+ ansible_host:$input.k8s_master_ip.public_ip,
+ private_ip:$input.k8s_master_ip.private_ip,
+} as $master |
-(cd .. && terraform output -json) | jq 'to_entries|map({(.key|tostring):.value.value})|add as $input | $input.k8s_node_ips|to_entries|map({("k8s-node"+(.key|tostring)):{ansible_host:.value}})|add + {"k8s-master":{ansible_host:$input.k8s_master_ip}}|{_meta:{hostvars:.}, all:(["k8s-master"] + ($input.k8s_node_ips|to_entries|map("k8s-node"+(.key|tostring)))) }'
+{_meta:{
+ hostvars:([{"k8s-master": $master}]+$nodes|add)},
+ all:(["k8s-master"] + ($input.k8s_node_names)),
+ "k8s-nodes":$input.k8s_node_names,
+}
+EOF
+
+set -euo pipefail
+(cd .. && terraform output -json) | jq "$script"