项目作者: nbering

项目描述 :
"Logical" provider for integrating with an Ansible Dynamic Inventory script.
高级语言: Go
项目地址: git://github.com/nbering/terraform-provider-ansible.git
创建时间: 2018-01-06T16:54:23Z
项目社区:https://github.com/nbering/terraform-provider-ansible

开源协议:Mozilla Public License 2.0

下载


Ansible Terraform Provider

A Terraform provider serving as an interop layer for an Ansible dynamic
inventory script
.

Read the introductory blog post for an explanation of the design
motivations behind this provider.

Installation

Installation can be accomplished in two different ways:

  1. For Terraform 0.13+ Use terraform required_providers block
  2. Installing a pre-compiled release (recommended)
  3. Compiling from source

For Terraform 0.13+ Use terraform required_providers block

providers.tf

  1. terraform {
  2. required_providers {
  3. ansible = {
  4. source = "nbering/ansible"
  5. version = "1.0.4"
  6. }
  7. }
  8. }
  9. provider "ansible" {}

then perform another init to download the provider.

  1. $ terraform init
  2. Initializing modules...
  3. Initializing the backend...
  4. Initializing provider plugins...
  5. - Finding nbering/ansible versions matching "1.0.4"
  6. ...
  7. - Installing nbering/ansible v1.0.4...
  8. - Installed nbering/ansible v1.0.4 (self-signed, key ID xxxxxxxxxxxxxx)
  9. ...
  10. Terraform has been successfully initialized!
  11. You may now begin working with Terraform. Try running "terraform plan" to see
  12. any changes that are required for your infrastructure. All Terraform commands
  13. should now work.

Installing a Pre-Compiled Release

Downloading and installing a pre-compiled terraform-provider-ansible release
is the recommended method of installation since it requires no additional tools
or libraries to be installed on your workstation.

  1. Visit the releases page and download the latest release for your target
    architecture.

  2. Unzip the downloaded file and copy the terraform-provider-ansible binary
    to a designated directory as described in Terraform’s plugin installation
    instructions
    .

Compiling From Source

Note: Terraform requires Go 1.11 or later to successfully compile.

Note: Dependencies are no longer included in this repository. You may need the
bazaar version control utility to download some of Terraform’s Go-lang
module dependencies.

If you’d like to take advantage of features not yet available in a pre-compiled
release, you can compile terraform-provider-ansible from source.

In order to compile, you will need to have Go installed on your workstation.
Official instructions on how to install Go can be found here.

Alternatively, you can use gimme as a quick and easy way to install Go:

  1. $ sudo wget -O /usr/local/bin/gimme https://raw.githubusercontent.com/travis-ci/gimme/master/gimme
  2. $ sudo chmod +x /usr/local/bin/gimme
  3. $ gimme 1.10
  4. # copy the output to your `.bashrc` and source `.bashrc`.

Once you have a working Go installation, you can compile
terraform-provider-ansible by doing the following:

  1. $ go get github.com/nbering/terraform-provider-ansible
  2. $ cd $GOPATH/src/github.com/nbering/terraform-provider-ansible
  3. $ make

You should now have a terraform-provider-ansible binary located at
$GOPATH/bin/terraform-provider-ansible. Copy this binary to a designated
directory as described in Terraform’s plugin installation instructions

Terraform Configuration Example

  1. resource "ansible_host" "example" {
  2. inventory_hostname = "example.com"
  3. groups = ["web"]
  4. vars = {
  5. ansible_user = "admin"
  6. }
  7. }
  8. resource "ansible_group" "web" {
  9. inventory_group_name = "web"
  10. children = ["foo", "bar", "baz"]
  11. vars = {
  12. foo = "bar"
  13. bar = 2
  14. }
  15. }

Compatibility

Version 1.0.0 of this project is compatible with Terraform version
0.12-beta2. You will also need 2.0.0+ of the terraform-inventory
script, as the internal structure of Terraform state files has changed.

If you need a version compatible with an earlier version of
Terraform, use version 0.0.4.

When upgrading to Terraform 0.12.x, you may need to change your configuration
files to reflect changes to the new version of the Hashicorp Configuration
Lanaguage (HCL). The only known incompatibility is that vars attributes now
require an equals operator (=).

0.11.x

  1. resource "ansible_host" "example" {
  2. inventory_hostname = "example.com"
  3. vars {
  4. ansible_user = "admin"
  5. }
  6. }

0.12.x

  1. resource "ansible_host" "example" {
  2. inventory_hostname = "example.com"
  3. vars = {
  4. ansible_user = "admin"
  5. }
  6. }

Alternatives and Similar Projects

jonmorehouse/terraform-provisioner-ansible

A Terraform Provisioner that runs Ansible-Local on a target machine at creation-time.

adammck/terraform-inventory

A very similar solution to this one, without the Logical provider. Depends on
specific Terraform resource types, and relies heavily on cloud-providers’ tag
implementations.

Ansible Collection: Terraform

An Ansible collection that runs Terraform plans and deployments.

License

Contributions specific to this project are made available under the
Mozilla Public License.

Code under the vendor/ directory is copyright of the various package owners,
and made available under their own license considerations.