One of the least used features in vSphere that I think almost all admins could really make use of but don’t is the ability to create custom vSphere tags within vSphere.
I wanted to take the time to point this feature out, and perhaps give people some ideas on how to make use of of them. This can help with management and automation quite a bit.
What are vSphere Tags?
vSphere Tags are effectively custom metadata type info that can be applied to objects within vCenter. You get to make your own to fit your own needs. They assist basically with locating objects for more efficient administration and management.
They’re unique to other things such as folders for your VMs in that you can assign multiple tags to the same VM or other objects.
Let’s break this down by comparing vSphere tags to MP3 management software like iTunes. An individual MP3 file must be in one file system folder or another. It can’t be in both. But suppose you want to find all your songs by an artist, by genre, or by album? We intuitively understand this now with MP3s.
But we have the same problem with VMs. You can organize your VMs into VM folders in vCenter, but a single VM can only be in one folder or another. What if you wanted to organize your VMs by criticality? By whether or not they have SQL? Whether or not they need to be backed up? Trying to do this with folders would be a nightmare to manage. Plus, remember a VM folder is the mechanism for assigning permissions, too. Maybe you don’t want this metadata having any impacts on anyone’s permissions to manage it.
That’s when you use vSphere tags!
Use Cases for vSphere Tags
Use cases for this functionality are numerous:
- Criticality of VM – this would allow the expedited power up or down of VMs based on this nature. Running out of resources within your cluster due to sudden host failures? Power down the non-critical VMs. It would also be helpful for vSphere Admins who aren’t the application admins to know when to handle a VM with care before doing anything to it.
- Application groupings – Maybe it doesn’t make sense to put VMs that work together to provide an application or service, but you want to know those groups. That could allow a SQL server that serves the backend of multiple application groups to be identified for both simultaneously.
- Presence of a common application like SQL – This can be helpful for locating VMs that may require special settings on backup jobs to quiesce the file system before backing the VM up. You might also use this to find potential VMs that other VMs are dependent on, so you can set their restart priority so they boot up first in an HA event scenario.
- Lab/Test VMs – You could set the resource allocation for Lab/Test VMs to low to help ensure they are given less resources than production VMs.
OK, I convinced you (hopefully)! Let’s make some tags.
Basic Concepts for vSphere Tags You Need To Know
You can create vSphere tags in both within the vSphere Web Client and with PowerCLI. It’s simple, but you need to know a few concepts.
All vSphere tags belong to a Category. There are two main types of categories. This notion is called Cardinality. It sounds more complicated than it is. Basically, you can have a category where only a single tag from that category can be applied to any given object. For example, let’s say you want to tag VMs by criticality. Logically, a VM will only have one criticality rating, not multiple. IE, it makes zero since for a VM to be both low and medium as far as how critical they are.
However, sometimes you might want a category that multiple tags could apply to the same object. For example, let’s say you want to make a category called “Special Applications” to identify very specific apps within a VM to easily identify SQL servers, Domain Controllers, and Exchange servers. While I wouldn’t recommend it, it’s possible for a single VM to be all three simultaneously.
vSphere tags can apply to all kinds of objects as well, not just VMs. You can select which objects a tag can be applied to within the category.
Managing vSphere Tags Using the Web Client
To create tags within the vSphere client, navigate to the Tags section of the web client.
You must create a category first if there isn’t one already made. Click the Categories button, and then click the create categories icon.
For this example, we will make a category for criticality ratings for VMs. We want one tag per object, not more, and we only want the tag to be applied to VMs or vApps.
Now that we have our category, we can create tags within it. Click on Tags, and the new tag icon. Be sure to select the category during tag creation.
Rinse and repeat for all the tags you want to create for the category. One tip I recommend is to name the tags with incuding their category name, which refers to some kind of concept. Since you usually search by the tag name, you want for example LowCriticality instead of Low. (See below for search examples.) Low in and of itself could mean a lot of things. Low resource usage, low criticality, etc.
To apply a tag to an object, simply right click the object, point to Tags & Custom Attributes > Assign Tag…
A new dialog box appears where you can filter categories or see all categories and select the vSphere tags you wish to assign. Also, notice you can remove tags here, too.
Managing vSphere Tags Using PowerCLI
PowerCLI has full tag management functionality within it, too.
Creating a category:
New-TagCategory -Name VMCriticality -Description "Criticality of the VM" -Cardinality Single -EntityType "VirtualMachine","VApp"
Creating a tag:
New-Tag -Name "LowCriticality" -Description "Non-Critical VMs" -Category VMCriticality
Assigning a tag to a VM:
get-vm Shoretel | New-TagAssignment -Tag "HighCriticality"
You can do lots of things with PowerCLI and tags.
Using vSphere Tags
Now that you have tags created and applied, you can now make use of them to make your life easier.
You can make use of tags in both the vSphere Web Client and via PowerCLI. To find all VMs with a tag within the vSphere Web Client, simply type the tag value in the search box. The tag name will automatically populate.
Click on it. Boom, you got your objects with that tag!
There’s also a parameter on PowerCLI’s Get-VM cmdlet to identify the VMs with that tag. You can then pipe that to another cmdlet. Say for example you want to shutdown your non-critical VMs because you suddenly experience multiple host failures, so you need to make sure your more important VMs get the resources they need:
Get-VM –Tag “LowCriticality” | Shutdown-VMGuest
Imagine if you set up vSphere tags to identity all your VMs with SQL. Imagine you’re setting up Veeam backup jobs, and you need to know which VMs you need to setup special quiescing. You could easily just get that list of VMs.
That’s how to use vSphere tags!
How do you think you might be able to use them, or how do you use them within your environment?