项目作者: RobotsAndPencils

项目描述 :
Transform Terraform state into Ansible inventories
高级语言: Python
项目地址: git://github.com/RobotsAndPencils/terrible.git
创建时间: 2015-05-08T22:58:57Z
项目社区:https://github.com/RobotsAndPencils/terrible

开源协议:Other

下载


Terrible

A command line tool for transforming terraform state into ansible inventory files

Terraform is great at deploying infrastructure. This project aims to make using ansible and terraform together easy.

Installing

  1. pip install git+git://github.com/RobotsAndPencils/terrible

Using

Write your terraform config as you usually would

  1. # app.tf
  2. resource "aws_instance" "app-server" {
  3. ami = "aminumber"
  4. instance_type = "t2.small"
  5. key_name = "keyname"
  6. count = 1
  7. tags {
  8. Name = "server"
  9. }
  10. connection {
  11. user = "ubuntu"
  12. key_file = "key_path"
  13. }
  14. }

Create a Jinja2 template for your ansible inventory file

  1. # ansible-inventory.j2
  2. # Inventory for provisioning app-server
  3. #
  4. {% for resource in resources %}
  5. {% for key, value in resource.iteritems() -%}
  6. {% if "aws_instance.app-server" in key %}
  7. [app-server]
  8. # you can reference any terraform attribute
  9. # https://www.terraform.io/docs/providers/aws/r/instance.html
  10. {{ value.primary.attributes.public_ip }} ansible_ssh_user=ubuntu
  11. {%- endif %}
  12. {%- endfor %}
  13. {%- endfor %}

Run terraform normally, then use terrible to convert terraform state to ansible inventory

  1. terraform plan
  2. terraform apply
  3. terrible --template-path $PWD \
  4. --template ansible-inventory.j2 \
  5. --tfstate terraform.tfstate \
  6. --inventory-output inventory.ini \

Now you can do normal ansible commands

  1. ansible app-server -m ping --inventory-file=inventory.ini

Contributing

  1. git clone git@github.com:RobotsAndPencils/terrible.git

You may want to set up a virtualenv by running virtualenv .venv; source .venv/bin/activate before you use the make file.

  1. make setup
  2. make test

Contact

Robots & Pencils Logo

Made with :heart: by Robots & Pencils (@robotsNpencils)

Maintainers