An Ansible dynamic inventory script to pair with nbering/terraform-provider-ansible.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore Add environment variable for terraform config directory. Jan 7, 2018 Update changelog for v1.0.1. Feb 26, 2018
LICENSE Initial commit for Python version - README and LICENSE. Jan 6, 2018 Fix env var in documentation to match implementation. Feb 26, 2018 Add support for ansible_group resource. Feb 26, 2018

Terraform Inventory

An Ansible dynamic inventory script to process Terraform state and return Ansible host data from Terraform Provider for Ansible host resources. See the Terraform Provider for it's own installation and use.


Copy the script file to a location on your system. Ansible's own documentation suggests the location /etc/ansible/, but the particular location does not matter to the script. Ensure it has executable permissions (chmod +x /etc/ansible/

With your Ansible playbook and Terraform configuration in the same directory, run Ansible with the -i flag to set the inventory source.

$ ansible-playbook -i /etc/ansible/ playbook.yml

Environment Variables


Override the path to the Terraform command executable. This is useful if you have multiple copies or versions installed and need to specify a specific binary. The inventory script runs the terraform state pull command to fetch the Terraform state, so that remote state will be fetched seemlessly regardless of the backend configuration.


Set the working directory for the terraform command when the scripts shells out to it. This is useful if you keep your terraform and ansible configuration in separate directories. Defaults to using the current working directory.


Licensed for use under the MIT License.