Closed jbilbro closed 7 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!"
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?
@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.
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.
@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. 😢
@rossedman , thanks for sharing. This works for me after being stumped for hours. Disregard the previous edit of my post - careless error.
@mr-future Awesome! Glad it helped someone. 👍
@jbilbro Do you mind closing this issue? Has this been solved?
@jbilbro thanks!
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?