chore: more effective ansible local-exec provision

This commit is contained in:
surtur 2021-05-20 06:08:13 +02:00
parent 4f200788b0
commit da7e1f9e4f
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -153,22 +153,27 @@ resource "libvirt_domain" "net-lab" {
provisioner "local-exec" { provisioner "local-exec" {
command = <<EOF command = <<EOF
echo "[defender]" > hosts echo "[defender]" > ${path.module}/../hosts
echo h_defender >> hosts echo h_defender >> ${path.module}/../hosts
echo "[defender:vars]" >> hosts echo "[defender:vars]" >> ${path.module}/../hosts
echo "[router]" >> hosts echo "[router]" >> ${path.module}/../hosts
echo r_upstream >> hosts echo r_upstream >> ${path.module}/../hosts
echo r_edge >> hosts echo r_edge >> ${path.module}/../hosts
echo "[router:vars]" >> hosts echo "[router:vars]" >> ${path.module}/../hosts
echo "[attacker]" >> hosts echo "[attacker]" >> ${path.module}/../hosts
echo h_attacker >> hosts echo h_attacker >> ${path.module}/../hosts
echo "[attacker:vars]" >> hosts echo "[attacker:vars]" >> ${path.module}/../hosts
echo "[victim]" >> hosts echo "[victim]" >> ${path.module}/../hosts
echo h_victim >> hosts echo h_victim >> ${path.module}/../hosts
echo "[victim:vars]" >> hosts echo "[victim:vars]" >> ${path.module}/../hosts
ansible-playbook -u ansible --private-key ${var.ssh_private_key} -i hosts playbooks/lab.yml sleep 200
cd ..; ansible-playbook -u ansible --private-key ${var.ssh_private_key} -i ${path.module}/hosts playbooks/lab.yml
EOF EOF
} }
provisioner "local-exec" {
command = "rm -v ${path.module}/hosts"
when = destroy
}
} }