Skip to content

Dynamic inventory script for Ansible to work with Terrraform deployed IBM Cloud Infrastructure

License

Notifications You must be signed in to change notification settings

stevestrutt/terraform_ansible_inventory_ibmcloud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform-Ansible dynamic inventory for IBM Cloud

Sample Python script to dynamically parse terraform.tfstate file into Ansible inventory

Copyright (c) 2018, IBM UK [email protected] ti_version = '0.6'

Ansible dynamic inventory for Terraform with IBM Cloud

This dynamic inventory script is written for use with Ansible and Terraform on IBM Cloud. Details of how to setup the script can be found in the IBM Cloud documentation. http://................................

Static and dynamic inventory

This script can be used alongside static inventory files in the same directory

Terraform dependencies

This inventory script expects to find Terraform tags of the form group: host_group associated with each tf instance to define the host group membership for Ansible. Multiple group tags are allowed per host

Configuration

To avoid co-mingling the Ansible and Terraform definitions in the same directory, the terraform.tfstate defining the current state of the deployed infrastructure, is read from the Terraform direcfory. This is specified using the
terraform_inv.ini file in the same directory as this script, pointing to the location of the terraform.tfstate file to be inventoried. The tfstate file should be referenced by is full path and file name.

[TFSTATE]
#TFSTATE_FILE = /nnn/nnn/nnn/tr_test_files/terraform.tfstate
#TFSTATE_FILE = /Users/JohnDoe/terraform/ibm/app2x/terraform.tfstate
#TFSTATE_FILE = /usr/share/terraform/ibm/app2x/terraform.tfstate

Testing

Validate correct execution:

  • With supplied test files - ./terraform_inv.py -t ../tr_test_files/terraform.tfstate
  • With ini file ./terraform.py --list Successful execution returns groups with lists of hosts and _meta/hostvars with a detailed host listing. Validate successful operation with ansible from the playbook directory:
  • ansible-inventory -i inventory --list

About

Dynamic inventory script for Ansible to work with Terrraform deployed IBM Cloud Infrastructure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages