From 1d2483bb1ba5e50f6551f4e33d8e275316133167 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Thu, 16 Jun 2022 18:06:53 +0200 Subject: [PATCH] terraform: rewrite ansible_inventory as yaml instead of ini --- terraform/outputs.tf | 2 +- .../{inventory.tmpl => inventory.ini.tmpl} | 0 terraform/templates/inventory.yml.tmpl | 37 +++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) rename terraform/templates/{inventory.tmpl => inventory.ini.tmpl} (100%) create mode 100644 terraform/templates/inventory.yml.tmpl diff --git a/terraform/outputs.tf b/terraform/outputs.tf index da1ce7a..821503e 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -1,5 +1,5 @@ resource "local_file" "ansible_inventory" { - content = templatefile("templates/inventory.tmpl", + content = templatefile("templates/inventory.yml.tmpl", { dns_gateways = gandi_livedns_record.mongo_gateways.* dns_servers = gandi_livedns_record.mongo_gateways.* diff --git a/terraform/templates/inventory.tmpl b/terraform/templates/inventory.ini.tmpl similarity index 100% rename from terraform/templates/inventory.tmpl rename to terraform/templates/inventory.ini.tmpl diff --git a/terraform/templates/inventory.yml.tmpl b/terraform/templates/inventory.yml.tmpl new file mode 100644 index 0000000..30439cb --- /dev/null +++ b/terraform/templates/inventory.yml.tmpl @@ -0,0 +1,37 @@ +all: + children: + all_groups: + children: + role_gateway: + hosts: +%{ for index, instance in mongo_gateways ~} + prod-gateway9: + ansible_host: ${instance.network[0].fixed_ip_v4} + ansible_user: debian + mongo_group_id: ${instance.metadata.mongo_group_id} + mongo_groups_count: ${ mongo_groups_count } + mongo_replicas_count: ${ mongo_replicas_count } + sshwifty_hostname: ${dns_gateways[index].name}.${dns_gateways[index].zone} +%{ endfor ~} + role_mongo: + hosts: +%{ for index, instance in mongo_servers ~} + ${ instance.name }: + ansible_host: ${instance.network[0].fixed_ip_v4} + ansible_user: debian + mongo_group_id: ${instance.metadata.mongo_group_id} + mongo_group_index: ${instance.metadata.mongo_group_index} + mongo_groups_count: ${ mongo_groups_count } + mongo_replicas_count: ${ mongo_replicas_count } +%{ endfor ~} + stage_development: {} + stage_production: + hosts: +%{ for index, instance in mongo_gateways ~} + ${ instance.name } : {} +%{ endfor ~} +%{ for index, instance in mongo_servers ~} + ${ instance.name } : {} +%{ endfor ~} + stage_testing: {} + ungrouped: {}