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: {}