Skip to content

Commit

Permalink
Update default inventory.yml template to not fail when machines are n…
Browse files Browse the repository at this point in the history
…ot used
  • Loading branch information
bryan-bar committed Aug 14, 2023
1 parent 2f66609 commit 1084e6d
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions edbterraform/data/templates/user/inventory.yml.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
all:
children:
# PEM servers: tags.type.pem_server
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
pemserver:
hosts:
%{ if lower(try(values.tags.reference_architecture, "")) == "edb-always-on" ~}
Expand All @@ -24,11 +24,11 @@ all:
%{ endfor ~}

# Barman servers: tags.type.barman_server
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "barman_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "barman_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
barmanserver:
hosts:
%{ endfor ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "barman_server"} ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "barman_server"} ~}
%{ if lower(try(values.tags.reference_architecture, "")) == "edb-always-on" ~}
barmandc${ 1 + tonumber(try(values.tags.index -2)) }:
%{ else ~}
Expand All @@ -38,14 +38,14 @@ all:
private_ip: ${ values.private_ip }
ansible_user: ${ values.operating_system.ssh_user }
ansible_ssh_private_key_file: ${ values.operating_system.ssh_private_key_file }
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
pem_agent: true
pem_server_private_ip: ${ values.private_ip }
%{ endfor ~}
%{ endfor ~}

# Postgres servers: tags.type.postgres_server
%{ for key,values in { for key,values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "postgres_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key,values in { for key,values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "postgres_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
primary:
hosts:
%{ if lower(try(values.tags.pg_type, "")) == "epas" ~}
Expand All @@ -57,32 +57,32 @@ all:
private_ip: ${ values.private_ip }
ansible_user: ${ values.operating_system.ssh_user }
ansible_ssh_private_key_file: ${ values.operating_system.ssh_private_key_file }
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "barman_server" && tonumber(try(values.tags.index, -1)) == 0} ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "barman_server" && tonumber(try(values.tags.index, -1)) == 0} ~}
barman: true
barman_server_private_ip: ${ values.private_ip }
barman_backup_method: postgres
%{ endfor ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "dbt2_client" } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "dbt2_client" } ~}
%{ if tonumber(try(values.tags.index, -1)) == 0 ~}
dbt2: true
%{ endif ~}
dbt2_client_private_ip${ 1 + tonumber(try(values.tags.index, -2)) }: ${ values.private_ip }
%{ endfor ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "hammerdb_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "hammerdb_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
hammerdb: true
hammerdb_server_private_ip: ${ values.private_ip }
%{ endfor ~}
%{ if tobool(try(values.tags.pooler_local, false)) && lower(try(values.tags.pg_pooler, "")) == "pgbouncer" ~}
pgbouncer: true
%{ endif ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
pem_agent: true
pem_server_private_ip: ${ values.private_ip }
%{ endfor ~}
standby:
hosts:
%{ endfor ~}
%{ for key,values in { for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "postgres_server" && tonumber(try(values.tags.index, 0)) != 0 } ~}
%{ for key,values in { for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "postgres_server" && tonumber(try(values.tags.index, 0)) != 0 } ~}
%{ if lower(try(values.tags.pg_type, "")) == "epas" ~}
epas${ 1 + tonumber(values.tags.index) }.${ values.tags.cluster_name }.internal:
%{ else ~}
Expand All @@ -92,37 +92,37 @@ all:
private_ip: ${ values.private_ip }
ansible_user: ${ values.operating_system.ssh_user }
ansible_ssh_private_key_file: ${ values.operating_system.ssh_private_key_file }
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "barman_server" && tonumber(try(values.tags.index, -1)) == 0} ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "barman_server" && tonumber(try(values.tags.index, -1)) == 0} ~}
barman: true
barman_server_private_ip: ${ values.private_ip }
barman_backup_method: postgres
%{ endfor ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "dbt2_client" } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "dbt2_client" } ~}
dbt2_client_private_ip${ 1 + tonumber(try(values.tags.index, -2)) }: ${ values.private_ip }
%{ endfor ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "hammerdb_server" && tonumber(try(values.tags.index, -1)) == 0} ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "hammerdb_server" && tonumber(try(values.tags.index, -1)) == 0} ~}
hammerdb: true
hammerdb_server_private_ip: ${ values.private_ip }
%{ endfor ~}
%{ if tobool(try(values.tags.pooler_local, false)) && lower(try(values.tags.pg_pooler, "")) == "pgbouncer" ~}
pgbouncer: true
%{ endif ~}
replication_type: ${ values.tags.replication_type }
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "postgres_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "postgres_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
upstream_node_private_ip: ${ values.private_ip }
%{ endfor ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
pem_agent: true
pem_server_private_ip: ${ values.private_ip }
%{ endfor ~}
%{ endfor ~}

# BDR servers: tags.type.bdr_server
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "bdr_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "bdr_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
primary:
hosts:
%{ endfor ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "bdr_server" } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "bdr_server" } ~}
%{ if lower(try(values.tags.pg_type, "")) == "epas" ~}
epas${ 1 + tonumber(try(values.tags.index, -2)) ~}:
%{ else ~}
Expand All @@ -132,34 +132,34 @@ all:
private_ip: ${ values.private_ip }
ansible_user: ${ values.operating_system.ssh_user }
ansible_ssh_private_key_file: ${ values.operating_system.ssh_private_key_file }
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index), -1) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index), -1) == 0 } ~}
pem_agent: true
pem_server_private_ip: ${ values.private_ip }
%{ endfor ~}
%{ endfor ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "bdr_witness_server" } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "bdr_witness_server" } ~}
%{ if lower(try(values.tags.pg_type, "")) == "epas" ~}
epas${ 1 + tonumber(try(values.tags.index, -2)) + length([ for key, values in servers.machines: key if lower(try(values.tags.type, "")) == "bdr_server"]) }:
epas${ 1 + tonumber(try(values.tags.index, -2)) + length([ for key, values in try(servers.machines, {}): key if lower(try(values.tags.type, "")) == "bdr_server"]) }:
%{ else ~}
pgsql${ 1 + tonumber(try(values.tags.index,-2)) + length([ for key, values in servers.machines: key if lower(try(values.tags.type, "")) == "bdr_server"]) }:
pgsql${ 1 + tonumber(try(values.tags.index,-2)) + length([ for key, values in try(servers.machines, {}): key if lower(try(values.tags.type, "")) == "bdr_server"]) }:
%{ endif ~}
ansible_host: ${ values.public_ip }
private_ip: ${ values.private_ip }
ansible_user: ${ values.operating_system.ssh_user }
ansible_ssh_private_key_file: ${ values.operating_system.ssh_private_key_file }
%{ for key, values in { for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index), -1) == 0 } ~}
%{ for key, values in { for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index), -1) == 0 } ~}
pem_agent: true
pem_server_private_ip: ${ values.private_ip }
%{ endfor ~}
%{ endfor ~}

# Pool connection servers: tags.type.pooler_server
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "pooler_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "pooler_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
${ values.tags.pooler_type }:
hosts:
%{ endfor ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "pooler_server" } ~}
%{ if length([ for key, values in servers.machines: key if lower(try(values.tags.type, "")) == "bdr_server"]) > 0 ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "pooler_server" } ~}
%{ if length([ for key, values in try(servers.machines, {}): key if lower(try(values.tags.type, "")) == "bdr_server"]) > 0 ~}
pgbouncer${ 1 + tonumber(try(values.tags.index, -2)) }:
%{ else ~}
${ lower(try(values.tags.pooler_type, "")) }-${ 1 + tonumber(try(values.tags.index, -2)) }.${ values.tags.cluster_name }.internal:
Expand All @@ -168,21 +168,21 @@ all:
private_ip: ${ values.private_ip }
ansible_user: ${ values.operating_system.ssh_user }
ansible_ssh_private_key_file: ${ values.operating_system.ssh_private_key_file }
%{ for key,values in { for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "postgres_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key,values in { for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "postgres_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
primary_private_ip: ${ values.private_ip }
%{ endfor ~}
%{ for key, values in {for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in {for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "pem_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
pem_agent: true
pem_server_private_ip: ${ values.private_ip }
%{ endfor ~}
%{ endfor ~}

# DBT2 servers: tags.type.dbt2_client
%{ for key, values in { for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "dbt2_client" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in { for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "dbt2_client" && tonumber(try(values.tags.index, -1)) == 0 } ~}
dbt2_client:
hosts:
%{ endfor ~}
%{ for key, values in { for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "dbt2_client" } ~}
%{ for key, values in { for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "dbt2_client" } ~}
dbt2_client${ 1 + tonumber(try(values.tags.index, -2)) }.${ values.tags.cluster_name }.internal:
ansible_host: ${ values.public_ip }
private_ip: ${ values.private_ip }
Expand All @@ -191,11 +191,11 @@ all:
%{ endfor ~}

# DBT2 servers: tags.type.dbt2_driver
%{ for key, values in { for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "dbt2_driver" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in { for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "dbt2_driver" && tonumber(try(values.tags.index, -1)) == 0 } ~}
dbt2_driver:
hosts:
%{ endfor ~}
%{ for key, values in { for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "dbt2_driver" } ~}
%{ for key, values in { for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "dbt2_driver" } ~}
dbt2_driver${ 1 + tonumber(try(values.tags.index, -2)) }.${ values.tags.cluster_name }.internal:
ansible_host: ${ values.public_ip }
private_ip: ${ values.private_ip }
Expand All @@ -204,11 +204,11 @@ all:
%{ endfor ~}

# HammerDB servers: tags.type.hammerdb_server
%{ for key, values in { for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "hammerdb_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
%{ for key, values in { for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "hammerdb_server" && tonumber(try(values.tags.index, -1)) == 0 } ~}
hammerdbserver:
hosts:
%{ endfor ~}
%{ for key, values in { for key, values in servers.machines: key=>values if lower(try(values.tags.type, "")) == "hammerdb_server" } ~}
%{ for key, values in { for key, values in try(servers.machines, {}): key=>values if lower(try(values.tags.type, "")) == "hammerdb_server" } ~}
hammerdbserver${ 1 + tonumber(try(values.tags.index, -2)) }.${ values.tags.cluster_name }.internal:
ansible_host: ${ values.public_ip }
private_ip: ${ values.private_ip }
Expand Down

0 comments on commit 1084e6d

Please sign in to comment.