mantl / terraform.py

Ansible dynamic inventory script for parsing Terraform state files
Apache License 2.0
451 stars 122 forks source link

vsphere provider? #48

Closed jbilbro closed 7 years ago

jbilbro commented 8 years ago

I'm confused how to make this work with the vsphere provider as it doesn't support tags? Can someone point me in the right direction, please?

rossedman commented 8 years ago

Here is an example of a Terraform resource and then how it is applied with Ansible. I am using a naming convention to make this work. There may be other ways to do this but this is what I found worked best for me.

resource "vsphere_virtual_machine" "web" {
  count  = 2
  name   = "web${count.index + 1}"
  domain = "web${count.index + 1}.${var.domain}"
  vcpu   = 2
  memory = 4096

  network_interface {
    label = "${var.vsphere_network}"
  }

  disk {
    datastore = "${var.vsphere_datastore}"
    template = "${var.vsphere_template}"
  }
}

And then the Ansible playbook

- hosts: web*
  sudo: yes
  tasks:
    - debug: msg="This is the web server!"
jbilbro commented 8 years ago

Thanks, that's helpful. I'm really trying to figure out how I can create dynamic groups out of this for the vsphere provider. Anyone been able to hack that?

rossedman commented 8 years ago

@jbilbro I am confused. This script creates a dynamic inventory. Ansible for vsphere is using the name instead of tags. AWS uses tags. What is shown above is how you create dynamic groups.

jbilbro commented 8 years ago

I think I misunderstood 'tags' as being like a group membership attribute. I was hoping there was a way to add a resource to multiple groups, but using the resource name in a wildcard will do most of what I'm looking for.

rossedman commented 8 years ago

@jbilbro This may have changed, but I thought this was more of a limitation of Terraform vSphere Provider rather than Ansible. I know exactly what you mean as I struggled with this quite a bit as well. The best solution I came up with was above. 😢

mr-future commented 7 years ago

@rossedman , thanks for sharing. This works for me after being stumped for hours. Disregard the previous edit of my post - careless error.

rossedman commented 7 years ago

@mr-future Awesome! Glad it helped someone. 👍

rossedman commented 7 years ago

@jbilbro Do you mind closing this issue? Has this been solved?

rossedman commented 7 years ago

@jbilbro thanks!