Skip to content

Commit

Permalink
Fix. Ansible provisioner shows pending changes each time. Make `argum…
Browse files Browse the repository at this point in the history
…ents` and `envs` variables not required (#14)
  • Loading branch information
SweetOps authored and const-bon committed Oct 13, 2017
1 parent 8c4af34 commit 04fb77c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 2 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ data "archive_file" "default" {
type = "zip"
source_dir = "${dirname(var.playbook)}"
output_path = "${path.module}/${random_id.default.hex}.zip"

depends_on = ["random_id.default"]
}

resource "null_resource" "provisioner" {
Expand All @@ -17,11 +15,11 @@ resource "null_resource" "provisioner" {

triggers {
signature = "${data.archive_file.default.output_md5}"
command = "ansible-playbook ${var.dry_run ? "--check --diff" : ""} ${join(" ", var.arguments)} -e ${join(" -e ", var.envs)} ${var.playbook}"
command = "ansible-playbook ${var.dry_run ? "--check --diff" : ""} ${join(" ", compact(var.arguments))} ${length(compact(var.envs)) > 0 ? "-e" : ""} ${join(" -e ", compact(var.envs))} ${var.playbook}"
}

provisioner "local-exec" {
command = "ansible-playbook ${var.dry_run ? "--check --diff" : ""} ${join(" ", var.arguments)} -e ${join(" -e ", var.envs)} ${var.playbook}"
command = "ansible-playbook ${var.dry_run ? "--check --diff" : ""} ${join(" ", compact(var.arguments))} ${length(compact(var.envs)) > 0 ? "-e" : ""} ${join(" -e ", compact(var.envs))} ${var.playbook}"
}

lifecycle {
Expand All @@ -37,6 +35,4 @@ resource "null_resource" "cleanup" {
provisioner "local-exec" {
command = "rm -f ${data.archive_file.default.output_path}"
}

depends_on = ["data.archive_file.default"]
}
10 changes: 7 additions & 3 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
variable "arguments" {
type = "list"
default = []
type = "list"
}

variable "envs" {
type = "list"
default = []
type = "list"
}

variable "playbook" {}
variable "playbook" {
default = ""
}

variable "dry_run" {
default = true
Expand Down

0 comments on commit 04fb77c

Please sign in to comment.