add condition to execut playbook
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
e7b507f566
commit
a5bf5ac889
6
main.tf
6
main.tf
|
@ -69,6 +69,8 @@ resource "xenorchestra_vm" "vm_deployed" {
|
||||||
|
|
||||||
# Generate inventory file
|
# Generate inventory file
|
||||||
resource "local_file" "inventory" {
|
resource "local_file" "inventory" {
|
||||||
|
count = var.playbook != "" ? 1 : 0
|
||||||
|
|
||||||
filename = "inventory"
|
filename = "inventory"
|
||||||
content = <<EOF
|
content = <<EOF
|
||||||
[all]
|
[all]
|
||||||
|
@ -77,12 +79,16 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "time_sleep" "wait_30_seconds" {
|
resource "time_sleep" "wait_30_seconds" {
|
||||||
|
count = var.playbook != "" ? 1 : 0
|
||||||
|
|
||||||
depends_on = [xenorchestra_vm.vm_deployed]
|
depends_on = [xenorchestra_vm.vm_deployed]
|
||||||
|
|
||||||
create_duration = "30s"
|
create_duration = "30s"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "null_resource" "run-ansible" {
|
resource "null_resource" "run-ansible" {
|
||||||
|
count = var.playbook != "" ? 1 : 0
|
||||||
|
|
||||||
provisioner "local-exec" {
|
provisioner "local-exec" {
|
||||||
command = "ansible-playbook -D -i inventory playbooks/${var.playbook} "
|
command = "ansible-playbook -D -i inventory playbooks/${var.playbook} "
|
||||||
environment = {
|
environment = {
|
||||||
|
|
2
var.tf
2
var.tf
|
@ -68,6 +68,7 @@ variable "template" {
|
||||||
|
|
||||||
variable "playbook" {
|
variable "playbook" {
|
||||||
type = string
|
type = string
|
||||||
|
default = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "cpu" {
|
variable "cpu" {
|
||||||
|
@ -96,4 +97,5 @@ variable "ssh_keys" {
|
||||||
|
|
||||||
variable "vm_tags" {
|
variable "vm_tags" {
|
||||||
type = list
|
type = list
|
||||||
|
default = []
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user