A dynamic inventory script for Ansible and Terraform.
To use this inventory script, you must first create Terraform resources using the terraform-provider-ansible plugin:
resource "ansible_host" "example" {
inventory_hostname = "example.com"
groups = ["web"]
vars {
ansible_user = "admin"
}
}
resource "ansible_group" "web" {
inventory_group_name = "web"
children = ["foo", "bar", "baz"]
vars {
foo = "bar"
bar = 2
}
}
Next, use this script as your Ansible dynamic inventory script.
If your Ansible playbooks are in a different directory than your Terraform
resources, then set the TF_STATE
environment variable to the location
of the Terraform directory.
Download the latest release.
$ go get github.com/jtopjian/ansible-terraform-inventory
$ go build -o $GOPATH/bin/terraform-inventory
$ ln -s $GOPATH/bin/terraform-inventory /path/to/ansible/hosts