I am getting familiar with Terraform and Ansible through books. Could someone enlighten me about the following block of code?
provisioner "local-exec" {
command = "ansible-playbook -u ubuntu --key-file ansible-key.pem -T 300 -i '${self.public_ip},', app.yml"
}
2
Answers
I would interpret that as Terraform should execute a local command on the Control Node.
Reading the documentation about
local-exec
Provisioner it turns out thatand not on the Remote Resource.
So after Terraform has in example created a Virtual Machine, it calls an Ansible playbook to proceed further on it.
The short answer is local-exec is for anything you want to do on your local machine instead of the remote machine.
You can do a bunch of different things:
~/.ssh
to access the serversleep 30
or something to make sure the next commands wait a bit for your machine to provisionFYI, hashicorp hates
local-
andremote-
exec. If you talk to one of their devs, they will tell you that it is a necessary evil. Other than maybe a sleep or write this or that, avoid it for any stateful data.