Skip to content

Unable to use vSphere tags #142

@chryzsh

Description

@chryzsh

I tried to create a basic example for this in my vSphere lab. I've applied the tf state below and the host is running.

When I run my test playbook as follows, the group is not matched
ansible-playbook --inventory-file=terraform-inventory ../ansible/ubuntu_test.yml -u ubuntu

Output

PLAY [foo_bar] **************************************************************************************************************************************************************
skipping: no hosts matched

I took a look at #123 and I had the impression the correct syntax would be {tag-category}_{tag-name} which led me to believe that for my example that would be foo_bar, but alas. I also tried category_bar and category_tag, but the result is the same.

Could you please look into this or tell me where I'm going wrong?

Files:
ubuntu_test.yml

- hosts: foo_bar
  tasks:
*snip*

main.tf

resource "vsphere_tag_category" "category" {
  name        = "foo"
  cardinality = "SINGLE"
  description = "Managed by Terraform"

  associable_types = [
    "VirtualMachine"
  ]
}

resource "vsphere_tag" "tag" {
  name        = "bar"
  category_id = vsphere_tag_category.category.id
  description = "Managed by Terraform"
}

# Creating the resource 
resource "vsphere_virtual_machine" "ubuntu-test" {
  name             = "ubuntu-test"
  resource_pool_id = data.vsphere_resource_pool.pool.id
  datastore_id     = data.vsphere_datastore.datastore.id

  num_cpus = 2
  memory   = 4096
  guest_id = data.vsphere_virtual_machine.ubuntu-template.guest_id
  
  scsi_type = data.vsphere_virtual_machine.ubuntu-template.scsi_type

  network_interface {
    network_id = data.vsphere_network.network.id
  }

  disk {
    label = "disk0"
    size  = 60
  }

  folder = "terraform"

  tags = ["${vsphere_tag.tag.id}"]
clone {
    template_uuid = data.vsphere_virtual_machine.ubuntu-template.id

     customize {
      linux_options {
        host_name = "ubuntu-test"
        domain    = "lab.local"
        time_zone = "Europe/Oslo"
      }

      dns_server_list = ["192.168.0.1"]

      network_interface {
        ipv4_address = "192.168.0.51"
        ipv4_netmask = 24
      }

      ipv4_gateway = "192.168.0.1"
      
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions