Update ansible inventory file when template changes (#1612)

This trigger ensures the inventory file is kept up-to-date. Otherwise, if the file exists and you've made changes to your terraform-managed infra without having deleted the file, it would never get updated. 

For example, consider the case where you've destroyed and re-applied the terraform resources, none of the IPs would get updated, so ansible would be trying to connect to the old ones.
This commit is contained in:
Yorgos Saslis 2017-09-05 14:10:53 +03:00 committed by Matthew Mosesohn
parent c77d11f1c7
commit 82eedbd622

View file

@ -176,6 +176,7 @@ data "template_file" "inventory" {
kube_insecure_apiserver_address = "kube_apiserver_insecure_bind_address: ${var.kube_insecure_apiserver_address}" kube_insecure_apiserver_address = "kube_apiserver_insecure_bind_address: ${var.kube_insecure_apiserver_address}"
} }
} }
resource "null_resource" "inventories" { resource "null_resource" "inventories" {
@ -183,4 +184,8 @@ resource "null_resource" "inventories" {
command = "echo '${data.template_file.inventory.rendered}' > ../../../inventory/hosts" command = "echo '${data.template_file.inventory.rendered}' > ../../../inventory/hosts"
} }
triggers {
template = "${data.template_file.inventory.rendered}"
}
} }