Module: ansible
Terraform Module to run ansible playbooks.
Usage
Add special section to the playbook
You must add this section on the top of all playbooks that will be used for provisioning.
This will add a dynamic inventory to target the host that needs provisioning.
e.g. ../ansible/playbooks/playbook.yml
- Create a runtime inventorty with an ip address of a host
- Wait for target host is ready for ssh connection
---
- hosts: localhost
gather_facts: True
check_mode: no
tasks:
- name: terraform-null-ansible
add_host:
name: terraform-null-ansible
groups: all
- local_action: wait_for port=22 host="{{ host }}" search_regex=OpenSSH delay=10
- hosts: all
gather_facts: False
check_mode: no
become: True
tasks:
- name: terraform-null-ansible
raw: >
test -e /usr/bin/python ||
(
(test -e /usr/bin/apt-get && (apt-get -y update && apt-get install -y python)) ||
(test -e /usr/bin/yum && (yum makecache fast && yum install -y python))
)
args:
creates: /usr/bin/python
Create an aws instance
resource "aws_instance" "web" {
ami = "ami-408c7f28"
instance_type = "t1.micro"
tags {
Name = test1
}
}
Apply the provisioner module to this resource
module "ansible_provisioner" {
source = "github.com/cloudposse/tf_ansible"
arguments = ["--user=ubuntu"]
envs = ["host=${aws_instance.web.public_ip}"]
playbook = "../ansible/playbooks/test.yml"
dry_run = false
}
Requirements
Name | Version |
---|---|
terraform | >= 0.12 |
archive | ~> 2.2.0 |
null | ~> 3.2.0 |
random | ~> 3.6.0 |
Providers
Name | Version |
---|---|
archive | ~> 2.2.0 |
null | ~> 3.2.0 |
random | ~> 3.6.0 |
Modules
No modules.
Resources
Name | Type |
---|---|
null_resource.cleanup | resource |
null_resource.provisioner | resource |
random_id.default | resource |
archive_file.default | data source |
Inputs
Name | Description | Type | Default | Required |
---|---|---|---|---|
arguments | Arguments | list(string) | [] | no |
dry_run | Do dry run | bool | true | no |
envs | Environment variables | list(string) | [] | no |
playbook | Playbook to run | string | "" | no |
Outputs
Name | Description |
---|---|
arguments | Arguments |
envs | Environment variables |