provisioner "local-exec" {
command = "ansible-playbook -i '${self.public_ip},' --private-key ${var.ssh_key_private} provision.yml"
}
provisioner "remote-exec" {
inline = ["sudo dnf -y install python"]
connection {
type = "ssh"
user = "fedora"
private_key = "${file(var.ssh_key_private)}"
}
}
provisioner "local-exec" {
command = "ansible-playbook -u fedora -i '${self.public_ip},' --private-key ${var.ssh_key_private} provision.yml"
}
$ ll infra
drwxrwxr-x. 3 avd avd 4.0K Mar 5 15:54 roles/
-rw-rw-r--. 1 avd avd 367 Mar 5 15:19 ansible.cfg
-rw-rw-r--. 1 avd avd 2.5K Mar 7 18:54 main.tf
-rw-rw-r--. 1 avd avd 454 Mar 5 15:27 variables.tf
-rw-rw-r--. 1 avd avd 38 Mar 5 15:54 provision.yml
$ terraform-inventory -inventory terraform.tfstate
[all]
52.51.215.84
[all:vars]
[server]
52.51.215.84
[server.0]
52.51.215.84
[type_aws_instance]
52.51.215.84
[name_c10k server]
52.51.215.84
[%_1]
52.51.215.84
$ ~/soft/terraform.py --root . --hostfile
## begin hosts generated by terraform.py ##
52.51.215.84 C10K Server
## end hosts generated by terraform.py ##
...
provisioner "ansible" {
plays {
playbook = "./provision.yml"
hosts = ["${self.public_ip}"]
}
become = "yes"
local = "yes"
}
...