Skip to content

Commit 03fe0ce

Browse files
s2504sconst-bon
authored andcommitted
Add option to use additional ansible ENV variables (#5)
1 parent fd5c0b4 commit 03fe0ce

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module "admin_tier" {
1313
source = "git::https://github.com/cloudposse/tf_instance.git?ref=master"
1414
ansible_playbook = "${var.ansible_playbook}"
1515
ansible_arguments = "${var.ansible_arguments}"
16+
ansible_envs = "${var.ansible_envs}"
17+
ansible_dry_run = "${var.ansible_dry_run}"
1618
ssh_key_pair = "${var.ssh_key_pair}"
1719
github_api_token = "${var.github_api_token}"
1820
github_organization = "${var.github_organization}"
@@ -60,6 +62,8 @@ resource "aws_ami_from_instance" "example" {
6062
| `github_team` | `` | GitHub team | Yes |
6163
| `ansible_playbook` | `` | Path to the playbook - required for `tf_ansible` (e.g. `./admin_tier.yml`) | Yes |
6264
| `ansible_arguments` | [] | List of ansible arguments (e.g. `["--user=ubuntu"]`) | No |
65+
| `ansible_envs` | [] | List of ansible envs (e.g. `["ansible_ssh_pass=${var.ansible_ssh_password}"]`) | No |
66+
| `ansible_dry_run` | `false` | The Ansible run without changes | No |
6367
| `instance_type` | `t2.micro` | The type of the creating instance (e.g. `t2.micro`) | No |
6468
| `vpc_id` | `` | The id of the VPC that the creating instance security group belongs to | Yes |
6569
| `security_groups` | [] | List of Security Group IDs allowed to connect to creating instance | Yes |
@@ -83,8 +87,10 @@ resource "aws_ami_from_instance" "example" {
8387
| Name | Description |
8488
|:--------------------|:-------------------------------------------------------------------|
8589
| `id` | Disambiguated ID |
86-
| `public_hostname` | Normalized name |
90+
| `public_dns` | Normalized name |
8791
| `public_ip` | Normalized namespace |
92+
| `private_dns` | Normalized name |
93+
| `private_ip` | Normalized namespace |
8894
| `ssh_key_pair` | Name of used AWS SSH key |
8995
| `security_group_id` | ID on the new AWS Security Group associated with creating instance |
9096
| `role` | Name of AWS IAM Role associated with creating instance |

main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ resource "aws_eip" "default" {
113113

114114
# Apply the provisioner module for this resource
115115
module "ansible" {
116-
source = "git::https://github.com/cloudposse/tf_ansible.git?ref=tags/0.3.0"
116+
source = "git::https://github.com/cloudposse/tf_ansible.git?ref=tags/0.3.4"
117117
arguments = "${var.ansible_arguments}"
118-
envs = ["host=${aws_eip.default.public_ip}"]
118+
envs = "${compact(concat(var.ansible_envs, list("host=${var.associate_public_ip_address ? aws_instance.default.public_dns : aws_instance.default.private_dns }")))}"
119119
playbook = "${var.ansible_playbook}"
120+
dry_run = "${var.ansible_dry_run}"
120121
}
121122

122123
# Restart dead or hung instance

variables.tf

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,23 @@ variable "ansible_playbook" {
1111
}
1212

1313
variable "associate_public_ip_address" {
14-
default = "true"
14+
default = true
1515
}
1616

1717
variable "ansible_arguments" {
1818
type = "list"
1919
default = []
2020
}
2121

22+
variable "ansible_envs" {
23+
type = "list"
24+
default = []
25+
}
26+
27+
variable "ansible_dry_run" {
28+
default = false
29+
}
30+
2231
variable "instance_type" {
2332
default = "t2.micro"
2433
}

0 commit comments

Comments
 (0)