add condition to execut playbook

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
Nicolas Boufidjeline 2022-07-01 19:31:17 +02:00
parent e7b507f566
commit a5bf5ac889
No known key found for this signature in database
GPG Key ID: 8DC009DF411D3BE1
2 changed files with 8 additions and 0 deletions

View File

@ -69,6 +69,8 @@ resource "xenorchestra_vm" "vm_deployed" {
# Generate inventory file
resource "local_file" "inventory" {
count = var.playbook != "" ? 1 : 0
filename = "inventory"
content = <<EOF
[all]
@ -77,12 +79,16 @@ EOF
}
resource "time_sleep" "wait_30_seconds" {
count = var.playbook != "" ? 1 : 0
depends_on = [xenorchestra_vm.vm_deployed]
create_duration = "30s"
}
resource "null_resource" "run-ansible" {
count = var.playbook != "" ? 1 : 0
provisioner "local-exec" {
command = "ansible-playbook -D -i inventory playbooks/${var.playbook} "
environment = {

2
var.tf
View File

@ -68,6 +68,7 @@ variable "template" {
variable "playbook" {
type = string
default = ""
}
variable "cpu" {
@ -96,4 +97,5 @@ variable "ssh_keys" {
variable "vm_tags" {
type = list
default = []
}