From da7e1f9e4f00b27015c81d34ac160f126ca0bd66 Mon Sep 17 00:00:00 2001 From: surtur Date: Thu, 20 May 2021 06:08:13 +0200 Subject: [PATCH] chore: more effective ansible local-exec provision --- vms/main.tf | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/vms/main.tf b/vms/main.tf index 36a84be..4e8417c 100644 --- a/vms/main.tf +++ b/vms/main.tf @@ -153,22 +153,27 @@ resource "libvirt_domain" "net-lab" { provisioner "local-exec" { command = < hosts - echo h_defender >> hosts - echo "[defender:vars]" >> hosts - echo "[router]" >> hosts - echo r_upstream >> hosts - echo r_edge >> hosts - echo "[router:vars]" >> hosts - echo "[attacker]" >> hosts - echo h_attacker >> hosts - echo "[attacker:vars]" >> hosts - echo "[victim]" >> hosts - echo h_victim >> hosts - echo "[victim:vars]" >> hosts - ansible-playbook -u ansible --private-key ${var.ssh_private_key} -i hosts playbooks/lab.yml + echo "[defender]" > ${path.module}/../hosts + echo h_defender >> ${path.module}/../hosts + echo "[defender:vars]" >> ${path.module}/../hosts + echo "[router]" >> ${path.module}/../hosts + echo r_upstream >> ${path.module}/../hosts + echo r_edge >> ${path.module}/../hosts + echo "[router:vars]" >> ${path.module}/../hosts + echo "[attacker]" >> ${path.module}/../hosts + echo h_attacker >> ${path.module}/../hosts + echo "[attacker:vars]" >> ${path.module}/../hosts + echo "[victim]" >> ${path.module}/../hosts + echo h_victim >> ${path.module}/../hosts + echo "[victim:vars]" >> ${path.module}/../hosts + sleep 200 + cd ..; ansible-playbook -u ansible --private-key ${var.ssh_private_key} -i ${path.module}/hosts playbooks/lab.yml EOF } + provisioner "local-exec" { + command = "rm -v ${path.module}/hosts" + when = destroy + } }