I have a long list of machines, all of which are a little different in functionality in a system. I'd like to organize these machines and add to a hosts inventory file automatically so I can run ansible and manage inventory. Are there good solutions out there for this?
I think ansible hosts should looks something like...
[webservers] someip someip [integration] someip someip
etc..
After asking the question, I currently am researching output vars and using those to render a template from a file.
Terraform and Ansible Ansible is a configuration-management and application-deployment tool. It means that you'll use Terraform first to create, for example, a virtual machine and then use Ansible to install necessary applications on that machine.
Terraform Inventory. This is a little Go app which generates a dynamic Ansible inventory from a Terraform state file. It allows one to spawn a bunch of instances with Terraform, then (re-)provision them with Ansible. The following providers are supported: AWS.
I figured it out.
data "template_file" "dev_hosts" { template = "${file("${path.module}/templates/dev_hosts.cfg")}" depends_on = [ "aws_instance.dev-api-gateway", "aws_instance.dev-api-gateway-internal", .... ] vars { api_public = "${aws_instance.dev-api-gateway.private_ip}" api_internal = "${aws_instance.dev-api-gateway-internal.private_ip}" } } resource "null_resource" "dev-hosts" { triggers { template_rendered = "${data.template_file.dev_hosts.rendered}" } provisioner "local-exec" { command = "echo '${data.template_file.dev_hosts.rendered}' > dev_hosts" } }
Then create a template in the file referenced earlier
Contents of example dev_hosts.cfg
[public] ${api_public} [private] ${api_internal}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With