When it comes to managing a VMware vSphere inventory, things can get crazy. Being able to determine what a virtual machine or other vSphere object actually does can be influence by any number of things from the naming convention in place, to who worked in the environment before you. The tag feature built into vSphere an amazing asset to any vSphere administrator, and also often one of the most overlooked. vSphere tags can be implemented a number of ways, such managing vSphere tags by using the web client, or managing vSphere tags with PowerCLI. As we all know, there are unique challenges that come with managing a number of vSphere assets. VMware vSphere tags simplify this.
Ready to find out how tags can make your life easier? Let’s start by taking a look at the two most important things you will need to be concerned with.
Introducing vSphere Tags and Categories
The two important things to think of when figuring out the best way to implement vSphere tags are the tags you are going to use along with the categories you are going to put them into. We are going to use the case of tagging virtual machines to illustrate this.
While there are a number of way to create tags in vSphere, we are going to start by right clicking the virtual machine we would like to tag, select Tags & Custom Attributes, then click Assign Tag.
When we are starting out we will not see much, so we are going to click the New tag button which is circled
Today we want to create tags based on applications. An application we work with is called Critical App, so we are going to name the tag Critical App. Then we will need to create a category, so we are going to select New Category from the drop down Category menu.
We will now be able to enter the information for our new category, which we are calling Applications since we are going to create unique tags for all of our applications.
As you can see, you can tag more than just virtual machines in your environment. You can associate a category with the following object types, or simply select All Objects.
- Content Library
- Datastore Cluster
- Distributed Port Group
- Distributed Switch
- Library Item
- Resource Pool
- Virtual Machine
Now, we have created a Tag for our application called Critical App, and created the new category of Applications. The only thing left to do is click OK to assign the Tag and the category to our virtual machine.
After we have created a tag and category, and they have been assigned to a virtual machine, we will see the tag and category on the summary screen of the virtual machine. This makes it easy to tell us exactly what a virtual machine or other vSphere object does at a glance if we implement tags and categories that make sense of our environment.
If we want to view our tags and categories in the vCenter web client, we can select Tags & Custom Attributes from the Home menu. We can also add Tags and Categories from this screen.
However, we have just tagged a single virtual machine using this process. I need still to tag the rest of the virtual machines in my cluster with the Critical App tag, since they all belong to our most critical application.
vSphere Tags and PowerCLI
Since we first used the vSphere web client to create and assign vSphere tags and categories, let’s try something else. Now I am going to use PowerCLI to tag the rest of the virtual machine in my cluster with the Critical App tag. PowerCLI has a number of commands that allow us to manage vSphere Tags and categories from the command line.
First, we will take a look at the Tags we have in our vCenter. After connecting to our vCenter with the Connect-VIServer command, we are going to type
Get-Tag. This will show us the tags we have in vCenter, along with their associated categories.
Now, to apply the Critical App tag to the rest of the virtual machines in my cluster named Site1-Cluster, I am going to use the command:
Get-Cluster Site1-Cluster | Get-VM | New-TagAssignment -Tag “Critical App”.
As you can see, the tag has been applied to my virtual machines.
If I wanted to create new tags and categories from PowerCLI, I could also do that. First, I can use the command:
New-TagCategory -Name “Applications” -Cardinality multiple -EntityType Virtual Machine
This creates a category named Applications for Virtual Machines. You may have noticed the
-Cardinality switch. Cardinality determines how many tags you can place per object. For example, if I created a Category named Tier, and the tags Production, Development, and Test within it, I may only want to allow one tag at a time to be applied to an Virtual Machine, since a Virtual Machine cannot be in the Production and Development tier at the same time. In this case I would use the cardinality attribute of single. On the other hand, I may have want a server to be able to be tagged with multiple applications at the same time, which I do in this case, so I used the multiple attribute when creating the vSphere tag category with PowerCLI.
After creating a category, I want to create a tag within the category. I can use the command:
New-Tag -Name “Important App” -Category “Applications”
to create a new tag named Important App in the Applications category. The, I can apply the tags to my virtual machines as we did previously.
New-TagAssignment -Tag "NameOfTag" -Entity VMName
Why Everyone Should Use vSphere Tags
vSphere tags can be helpful in a number of cases. The use case we have mostly talked about tagging virtual machines by application. Using tags at the application level can help make day to day activities such as troubleshooting and backing up applications easier by giving us a quick overview of the components that make up an application. Another use case we briefly talked about is tagging components by Tier to quickly identify Production, Dev, and Test objects. We may want to use tags on Datastores to tag each datastore with the array name instead of giving datastores long and confusing names. The possibilities are endless with vSphere tags, and they are a great feature to help make vSphere environments easier to manage.
More vSphere Tag Resources
As you can see from these examples, vSphere tags are not difficult to use once you get the hang of it, and are a very powerful too. The best place to find more information on vSphere tags is the Official vSphere Documentation. In addition, it may make sense to start by making a list of the vSphere tags and categories you would like to implement in your environment so you can quickly and easily implement them like we just did with PowerCLI.