Dynamic inventory for ansible using terraform

Hi There,

Does anyone know , how to run ansible playbook inside terraform after creating inventory during the terraform apply, below is my command and need some help on local-exec provisioner section

the error keeps saying unsupported argument for ansible, which is a valid one but i dont get an idea on how to resolve it

resource "local_file" "inventory" {
 filename = "./inventory"
 content = <<EOF
[ec2]
${aws_instance.ec2[0].private_ip}
${aws_instance.ec2[1].private_ip}
EOF
}

resource "null_resource" "null_1" {

  provisioner "local-exec" {
    command = "sleep 60 ;  ansible-playbook -i inventory , --private-key ${local.private_key_path} httpd.yaml"
  }
}

Hi @huzoor.bea,

I’m not really familiar with Ansible at all and so perhaps this is the wrong direction, but in your example I notice there’s a comma in the command line after -i inventory, which seems like an unusual design for a command line so I wonder if that comma is what is causing the error you’ve seen.