Add dynamic ansible inventory from terraform state
This commit is contained in:
parent
bccc07f806
commit
70578f2a13
11 changed files with 84 additions and 51 deletions
34
main.tf
34
main.tf
|
@ -1,5 +1,10 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
ansible = {
|
||||
source = "ansible/ansible"
|
||||
version = "1.2.0"
|
||||
}
|
||||
|
||||
aws = {
|
||||
source = "hashicorp/aws"
|
||||
version = "~> 5.0"
|
||||
|
@ -158,3 +163,32 @@ module "services" {
|
|||
|
||||
services = var.services
|
||||
}
|
||||
|
||||
|
||||
|
||||
resource "random_password" "host_backup_gatus_tokens" {
|
||||
for_each = module.infrastructure.hosts
|
||||
length = 32
|
||||
special = false
|
||||
}
|
||||
|
||||
resource "ansible_host" "nodes" {
|
||||
for_each = module.infrastructure.hosts
|
||||
name = each.value.hostname
|
||||
groups = ["serguzim_net"]
|
||||
|
||||
variables = {
|
||||
# Connection vars.
|
||||
ansible_host = each.value.fqdn_vpn
|
||||
ansible_port = 17
|
||||
ansible_user = "ansible"
|
||||
|
||||
# Custom vars that we might use in roles/tasks.
|
||||
host_vpn_domain = each.value.fqdn_vpn
|
||||
host_vpn_ip = each.value.ipv4_address_vpn
|
||||
|
||||
host_backup_hc_uid = module.infrastructure.healthchecksio.backup[each.key].id
|
||||
host_backup_hc_url = module.infrastructure.healthchecksio.backup[each.key].ping_url
|
||||
host_backup_gatus_token = random_password.host_backup_gatus_tokens[each.key].result
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue