Last active
February 25, 2020 07:08
-
-
Save NickLarsenNZ/7751278edd10ac5a01e1a221acbc40ce to your computer and use it in GitHub Desktop.
Coudera Ansible Inventory Generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "local_file" "inventory" { | |
content = templatefile("templates/inventory.tmpl", { | |
# map(string) | |
vars = var.global_vars | |
# string | |
scm_server = var.scm_server | |
db_server = var.db_server | |
krb5_server = var.krb5_server | |
# set(string) | |
gateway_servers = tolist(var.gateway_servers) | |
edge_servers = tolist(var.edge_servers) | |
master_servers = tolist(var.master_servers) | |
worker_servers = tolist(var.worker_servers) | |
}) | |
filename = var.output_file_path | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[scm_server] | |
${scm_server} | |
[db_server] | |
${db_server} | |
[krb5_server] | |
${krb5_server} | |
[utility_servers:children] | |
scm_server | |
db_server | |
krb5_server | |
[gateway_servers] | |
%{ for index,host in gateway_servers ~} | |
${host} host_template=HostTemplate-Gateway | |
%{ endfor ~} | |
[edge_servers] | |
%{ for index,host in edge_servers ~} | |
${host} host_template=HostTemplate-Edge role_ref_names=HDFS-HTTPFS-${index+1} | |
%{ endfor ~} | |
[master_servers] | |
%{ for index,host in master_servers ~} | |
${host} host_template=HostTemplate-Master${index+1} | |
%{ endfor ~} | |
[worker_servers] | |
%{ for index,host in worker_servers ~} | |
${host} | |
%{ endfor ~} | |
[worker_servers:vars] | |
host_template=HostTemplate-Workers | |
[cdh_servers:children] | |
utility_servers | |
gateway_servers | |
master_servers | |
worker_servers | |
[all:vars] | |
%{ for attr,val in vars ~} | |
${attr}=${val} | |
%{ endfor ~} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "output_file_path" { | |
description = "Path to write the inventory file to" | |
type = string | |
} | |
variable "global_vars" { | |
description = "Map of global Ansible variables" | |
type = map(string) | |
default = { | |
ansible_user = "ubuntu" | |
} | |
} | |
variable "scm_server" { | |
description = "Single SCM host" | |
default = "scm.localhost" | |
} | |
variable "db_server" { | |
description = "Single DB host" | |
default = "db.localhost" | |
} | |
variable "krb5_server" { | |
description = "Single Kerberos host" | |
default = "krb.localhost" | |
} | |
variable "gateway_servers" { | |
description = "List of Gateway hosts" | |
type = set(string) | |
default = ["gw.localhost"] | |
} | |
variable "edge_servers" { | |
description = "List of Edge hosts" | |
type = set(string) | |
default = ["e1.localhost"] | |
} | |
variable "master_servers" { | |
description = "List of Master hosts" | |
type = set(string) | |
default = ["m1.localhost", "m2.localhost", "m3.localhost"] | |
} | |
variable "worker_servers" { | |
description = "List of Worker hosts" | |
type = set(string) | |
default = ["w1.localhost", "w2.localhost", "w3.localhost", "w3.localhost"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[scm_server] | |
scm.localhost | |
[db_server] | |
db.localhost | |
[krb5_server] | |
krb.localhost | |
[utility_servers:children] | |
scm_server | |
db_server | |
krb5_server | |
[gateway_servers] | |
gw.localhost host_template=HostTemplate-Gateway | |
[edge_servers] | |
e1.localhost host_template=HostTemplate-Edge role_ref_names=HDFS-HTTPFS-1 | |
[master_servers] | |
m1.localhost host_template=HostTemplate-Master1 | |
m2.localhost host_template=HostTemplate-Master2 | |
m3.localhost host_template=HostTemplate-Master3 | |
[worker_servers] | |
w1.localhost | |
w2.localhost | |
w3.localhost | |
[worker_servers:vars] | |
host_template=HostTemplate-Workers | |
[cdh_servers:children] | |
utility_servers | |
gateway_servers | |
master_servers | |
worker_servers | |
[all:vars] | |
ansible_user=ubuntu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
<env>.tfvars
to override the input variables for each environment.Tip: expand the set/lists over multiple lines so as they change, version control diffs stays pretty.