Whilst continuing to prepare for my VMware Certified Advanced Professional Deploy Exam, I have been configuring vSphere Auto Deploy. As with my blog post on vCenter Profiles, I am covering Auto Deploy as its not something I have ever used in any great depth. As always, I used the official VMware documentation to guide me.
Lets get started!
In my lab I am using vCenter 7.0 Update 3c and using nested hosts for the Auto Deploy hosts. I am also using a RHEL server for the TFTP requirement along with DHCP provided by my layer 3 switch.
Depending on whether you are using BIOS or UEFI you will need to set the appropriate DHCP options; 66 & 67.
I am using EFI, therefore using UEFI DHCP Boot File Name : snponly64.efi.vmw-hardwired as the value for DHCP option 067.
In the vSphere Client Select the Auto Deploy menu:
If you haven’t setup Auto Deploy previously, click Enable Auto Deploy and Image Builder.
You now need to download the required files, including the boot files mentioned earlier, that you will need to host on your TFTP server by selecting the Download TFTP Zip File link:
Copy the downloaded file to your TFTP server using something like WinSCP and extract the ZIP file to the TFTPRoot directory you configured as part of the TFTP server installation/setup.
Your directory should then look something like this:
Now using PowerShell 5.1 (PowerShell 7 is not supported by the VMware.ImageBuilder module), connect to the vCenter Server and run the following commands to set up the software depots:
You can check you have added the depot successfully by running the following:
Get-EsxImageProfile
Now to create the Deploy Rules. I will be using the latest image; ESXi-7.0U3c-19193900-standard, deploying to my ‘virtual-cluster’ and providing it with a host profile I already had. I have also provided an IP address range for the hosts I want to include. You can also just use the ‘-AllHosts’ parameter if you don’t want to restrict.
My host profile contains a few basic settings such as the root password, NTP settings & NIC configurations. There are plenty of host configuration options that can be set in this profile, configure the settings you need for your environment or lab.
You will be able to see the rules in the vSphere Client once complete.
<Side Note>
If you want to be able to manually add rules in the vSphere Client, you will need to manually add the software depot using the same URL used earlier.
You will then be able to manually create Deploy Rules.
</Side Note>
Now back to it…
You will see the Deploy Rule is currently inactive:
Running the following activates the rule:
Add-DeployRule -DeployRule "Lab Auto Deploy Rule"
You can now see the status is Active in the UI.
If using the vSphere Client, you can use the ‘Activate/Deactivate Rules’ button instead if you didn’t want to use PowerShell.
Now before we start deploying hosts, we need to create some! In this case they will be nested hosts with minimum configurations. We will also need some DHCP reservations and appropriate DNS records.
Once in place, we can go ahead an boot the hosts.
Now heading back to the vSphere UI, you will find your newly deployed host(s)!
From a troubleshooting perspective, you will be wanting to take a look in syslog.log on the host. This helped me identify my issues when I hadn’t applied a firewall rule correctly!
As always, thanks for reading!
If you like my content, consider following me on Twitter so you don’t miss out!
Following the last blog post on create vSphere Port Groups, let’s take a look at creating Tags and Tag Categories.
Let’s first look at the process via the GUI, in this case, the vSphere Client. (Based on vSphere 7.0.3c)
vSphere Client
I wont go into to much detail here as this information is readily available, but here is a brief run through.
After logging into the vSphere Client, select the menu followed by Tags & Custom Attributes.
You the have the option to select either Tags or Categories, followed by the ‘New’ option.
For Categories you need to provide the Category name, optional description, the cardinality (single or multiple) and select the objects that can have this tag associated with it.
Then with Tags, you need to provide the name, optional description and the category the tag will be part of.
Now this may be ok for one or two, but if you need to create in bulk, this will take a while! Lets look as some alternatives.
PowerShell
Firstly, PowerShell, specifically the VMware PowerCLI PowerShell module. Here are examples of the using the cmdlets New-TagCategory and New-Tag to create the same thing we did in the vSphere Client.
Below is the output from PowerShell after running the script above:
Name Cardinality Description
---- ----------- -----------
costcentre Multiple Created with PowerCLI
Name Category Description
---- -------- -----------
0001 costcentre Created with PowerCLI
Now this isn’t much quicker than doing it in the vSphere Client so here is one way to create in bulk.
Here is a custom array with multiple categories and the additional values needed to create a Category.
Name Cardinality Description
---- ----------- -----------
costcentre Multiple Created with PowerCLI
environment Single Created with PowerCLI
nsx-tier Multiple Created with PowerCLI
Name Category Description
---- -------- -----------
0001 costcentre Created with PowerCLI
0002 costcentre Created with PowerCLI
0003 costcentre Created with PowerCLI
0004 costcentre Created with PowerCLI
environment environment Created with PowerCLI
production environment Created with PowerCLI
pre-production environment Created with PowerCLI
test environment Created with PowerCLI
development environment Created with PowerCLI
web nsx-tier Created with PowerCLI
app nsx-tier Created with PowerCLI
data nsx-tier Created with PowerCLI
That is just one way to create multiple Categories and Tags. You could take this information from a CSV file using the ‘Get-Content’ cmdlet as an alternative to creating the array manually.
Terraform
Now let’s take a look at using Terraform to achieve the same result. Terraform is an infrastructure and code tool used to manage infrastructure in the form of configuration files and state:
First we are specifying which terraform provider we want to use, this will be the vSphere provider in this case. We are then providing some parameters for the provider to connect to your vCenter instance; VCSA FQDN and credentials. You would want make use of variables for this data, but for this blog I am keeping it simple.
We then have three vsphere_tag_category resource blocks, one for each of the categories we want to create. This again provides values for cardinality and associable types like we did in PowerShell.
Next we are going to create the tags, but I am going to use a set of local variables to then pass into the three vsphere_tag resource blocks to reduce the amount of repeating code.
Here are the local variables. This is similar to creating the array we did in PowerShell.
And then the resource blocks, notice the for_each parameter. For each Tag Category, it will cycle through each value in the locals array for each category. This is just like we did in PowerShell foreach function earlier.
resource "vsphere_tag" "costcentre-tags" {
for_each = toset(local.costcentre_tags)
name = each.key
category_id = vsphere_tag_category.costcentre.id
description = "Managed by Terraform"
}
resource "vsphere_tag" "environment-tags" {
for_each = toset(local.environment_tags)
name = each.key
category_id = vsphere_tag_category.environment.id
description = "Managed by Terraform"
}
resource "vsphere_tag" "nsx-tier-tags" {
for_each = toset(local.nsx_tier_tags)
name = each.key
category_id = vsphere_tag_category.nsx-tier.id
description = "Managed by Terraform"
}
Now when we run ‘terraform apply’ from the command line to apply for code, this is the output:
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# vsphere_tag.costcentre-tags["0001"] will be created
+ resource "vsphere_tag" "costcentre-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "0001"
}
# vsphere_tag.costcentre-tags["0002"] will be created
+ resource "vsphere_tag" "costcentre-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "0002"
}
# vsphere_tag.costcentre-tags["0003"] will be created
+ resource "vsphere_tag" "costcentre-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "0003"
}
# vsphere_tag.costcentre-tags["0004"] will be created
+ resource "vsphere_tag" "costcentre-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "0004"
}
# vsphere_tag.environment-tags["development"] will be created
+ resource "vsphere_tag" "environment-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "development"
}
# vsphere_tag.environment-tags["pre-production"] will be created
+ resource "vsphere_tag" "environment-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "pre-production"
}
# vsphere_tag.environment-tags["production"] will be created
+ resource "vsphere_tag" "environment-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "production"
}
# vsphere_tag.environment-tags["test"] will be created
+ resource "vsphere_tag" "environment-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "test"
}
# vsphere_tag.nsx-tier-tags["app"] will be created
+ resource "vsphere_tag" "nsx-tier-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "app"
}
# vsphere_tag.nsx-tier-tags["data"] will be created
+ resource "vsphere_tag" "nsx-tier-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "data"
}
# vsphere_tag.nsx-tier-tags["web"] will be created
+ resource "vsphere_tag" "nsx-tier-tags" {
+ category_id = (known after apply)
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "web"
}
# vsphere_tag_category.costcentre will be created
+ resource "vsphere_tag_category" "costcentre" {
+ associable_types = [
+ "Datastore",
+ "VirtualMachine",
]
+ cardinality = "MULTIPLE"
+ description = "Managed by Terraform"
+ id = (known after apply)
+ name = "costcentre"
}
# vsphere_tag_category.environment will be created
+ resource "vsphere_tag_category" "environment" {
+ associable_types = [
+ "Datastore",
+ "VirtualMachine",
]
vsphere_tag.environment-tags["production"]: Creating...
vsphere_tag.environment-tags["pre-production"]: Creating...
vsphere_tag_category.nsx-tier: Creation complete after 0s [id=urn:vmomi:InventoryServiceCategory:20a2167a-b0f8-4a60-9d29-6c7ca57711ef:GLOBAL]
vsphere_tag.nsx-tier-tags["data"]: Creating...
vsphere_tag.nsx-tier-tags["app"]: Creating...
vsphere_tag.nsx-tier-tags["web"]: Creating...
vsphere_tag_category.costcentre: Creation complete after 0s [id=urn:vmomi:InventoryServiceCategory:28a909f5-ee41-4d94-b228-b5e96e09284e:GLOBAL]
vsphere_tag.costcentre-tags["0004"]: Creating...
vsphere_tag.costcentre-tags["0002"]: Creating...
vsphere_tag.costcentre-tags["0003"]: Creating...
vsphere_tag.environment-tags["development"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:5b63e350-ef6e-4bbc-a633-09c9047b327b:GLOBAL]
vsphere_tag.costcentre-tags["0001"]: Creating...
vsphere_tag.environment-tags["pre-production"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:e2a8737c-e42a-4c6f-b9a8-716a1681d0c0:GLOBAL]
vsphere_tag.nsx-tier-tags["data"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:b9d3394d-388c-4018-b7b2-9e4d3da8287b:GLOBAL]
vsphere_tag.costcentre-tags["0002"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:8a482528-5d67-40e9-86cb-4dbf566f85ac:GLOBAL]
vsphere_tag.nsx-tier-tags["web"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:5a325904-4dfd-46ac-b0db-37fd6fda1533:GLOBAL]
vsphere_tag.environment-tags["production"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:89c609b9-7f90-457d-9f71-0bd0b7cc667d:GLOBAL]
vsphere_tag.nsx-tier-tags["app"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:45c2dd0e-533a-4917-82be-987d3245137a:GLOBAL]
vsphere_tag.costcentre-tags["0004"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:230db56e-7352-4e14-ba63-0ad4b4c0ba18:GLOBAL]
vsphere_tag.environment-tags["test"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:ebcf1809-8cae-4cb2-a5fa-82a492e54227:GLOBAL]
vsphere_tag.costcentre-tags["0001"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:e4649ad2-08d2-4dcd-aabf-4e2d74f93a36:GLOBAL]
vsphere_tag.costcentre-tags["0003"]: Creation complete after 0s [id=urn:vmomi:InventoryServiceTag:18de9eca-456c-4539-ad6c-19d625ac5be7:GLOBAL]
Apply complete! Resources: 14 added, 0 changed, 0 destroyed.
For more information on the vSphere provider from Terraform, check out this link.
I hope this has given you some idea’s on how you can perhaps leverage other options beside the GUI, especially when looking to build or configure in bulk. All the code in this blog can be found on my GitHub here.
I recently came across an issue with creating subscribed VMware Content Libraries, and deploying templates from a Content Library.
An error similar to the one below, would be received when attempting to deploy a VM template or OVF from a Content Library, or an error related to connection issues when setting up a subscribed Content Library.
Failed to deploy OVF Package. ThrowablePrxy.cause A general system error occurred: Transfer failed.
After some investigation, I came to see that vCenter was attempting to communicate with linked vCenter’s and hosts via the web proxy that was configured in the VAMI, when attempting to deploy an OVF from a Content Library or when trying to synchronise a library.
As I didn’t want this traffic going via the proxy as it is internal traffic, a support ticket was logged. It was advised to add proxy exceptions, or bypasses, to the proxy file located here on a vCenter Server Appliance:
/etc/sysconfig/proxy
As this information isn’t something I managed to find documented publicly and support couldn’t provide me with anything as they were using internal documentation to assist, I thought I would write a quick post on it to help anyone facing the same issue!
Note: Always test in a non production environment and contact official support channels!
To begin reviewing and editing this file, you will need to SSH to the VCSA using the below command using your SSH tooling of choice.
ssh root@vm-vcsa-01.smt-lab.local
Using the following cat command you can then view the file:
cat /etc/sysconfig/proxy
Here is what the default file looks like with the HTTP and HTTPS options set:
# Enable a generation of the proxy settings to the profile.
# This setting allows to turn the proxy on and off while
# preserving the particular proxy setup.
#
PROXY_ENABLED="no"
# Some programs (e.g. wget) support proxies, if set in
# the environment.
# Example: HTTP_PROXY="http://proxy.provider.de:3128/"
HTTP_PROXY="proxy.smt-lab.local"
# Example: HTTPS_PROXY="https://proxy.provider.de:3128/"
HTTPS_PROXY="proxy.smt-lab.local"
# Example: FTP_PROXY="http://proxy.provider.de:3128/"
FTP_PROXY=""
# Example: GOPHER_PROXY="http://proxy.provider.de:3128/"
GOPHER_PROXY=""
# Example: SOCKS_PROXY="socks://proxy.example.com:8080"
SOCKS_PROXY=""
# Example: SOCKS5_SERVER="office-proxy.example.com:8881"
SOCKS5_SERVER=""
# Example: NO_PROXY="www.me.de, do.main, localhost"
NO_PROXY="localhost, 127.0.0.1"
Take note of the section at the bottom, “NO_PROXY”. This is where we need to add the fqdn’s of any hosts and VCSA’s you wish to deploy to, or subscribe with. If however you don’t want to maintain this for each and every host, you can add a wild card:
.*.domain.name
Note the ‘.’ at the beginning!
For instance, in my lab I would add the following entry to the NO_PROXY list:
.*.smt-lab.local
To edit this we can use the VI editor (More info on using VI here.):
vi /etc/sysconfig/proxy
Edit the file to include the FQDN’s or a wildcard, based on your requirements.
As technology moves forward, more and more ways to achieve your goal become available. Many people still rely on the good old trusty GUI to achieve their goal, I know I do at times. Is this because it’s quicker, more comfortable or familiar? Or perhaps because they don’t realise there are other options out there!?
This blog post will be one of many, where I highlight some of the options available for completing various technical tasks or configurations, in the hope it can provide additional options or tools for consideration.
To kick off, let’s take a look at a common example for a vSphere Administrator, creating Port Groups on a Distributed Switch.
vSphere Client
So let’s first look at the process via the GUI, in this case, the vSphere Client. I wont go into too much detail on the steps involved, as it is a well documented process, but the screenshots are below:
Repeat for the remaining Port Groups and you will be left with the finished article.
And there we have it, three Port Groups on a distributed Switch. Now, imagine doing this for 10’s or 100’s of Port Groups? It’s going to be slow and painful, so let’s look at some other options.
PowerShell
Firstly, PowerShell, specifically the VMware PowerCLI PowerShell module. Here is an example script that will create the same three Port Groups that we did using the GUI:
So lets break down this code. Firstly we are defining some variables;
$vDSName – This is the name of an existing virtual distributed switch in which you will be creating your Port Groups.
$Ports – This defines the number of ports the Port Group will be initially configured with. (By default 128 ports are created, there is nothing wrong with using the default, see the note further down as to why I have specified 8.)
$LoadBalancing – This is the load balancing policy I wish to set for the Port Group. Available options are:LoadBalanceLoadBased, LoadBalanceIP, LoadBalanceSrcMac, LoadBalanceSrcId, ExplicitFailover. This can be adjusted as required.
$ActiveUP – This variable defines the uplinks you wish to set as active for the Port Group. (If you want to add standby uplinks, you could add this parameter in too)
$VDPGS – Finally, this is an array containing both the name and VLAN ID for each Port Group.
Now we have our input information in variables, we move onto the next two lines of code. These are within a ‘ForEach Loop’. This will take each entry within an array and run a block of code against it. In this case, each Port Group we wish to create.
So for each entry in the array, ‘Get-VDswitch -Name $vDSName‘ gets the existing Virtual Distributed Switch based on the variable and then pipes (‘|’) this into the command (New-VDPortGroup -Name $VDPG.PG -VLanId $VDPG.VLANID -NumPorts $Ports) to create the Port Group on the Distributed Switch, using the properties set for each line of the array.
Secondly, we get the Port Group we just created (Get-VDswitch -Name $vDSName | Get-VDPortgroup $VDPG.PG) and then ‘Get & Set’ the Teaming and Loadbalancing options (Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy $LoadBalancing -ActiveUplinkPort $ActiveUP), again ‘piping’ the results into the next command.
Below is the output from PowerShell after running the script above:
Now let’s take a look at using Terraform to achieve the same result. Terraform is an infrastructure and code tool used to manage infrastructure in the form of configuration files and state:
provider "vsphere" {
vsphere_server = "vCenter Server FQDN"
user = "Domain\\Username"
password = "Password"
}
data "vsphere_datacenter" "datacenter" {
name = "dc-smt-01"
}
data "vsphere_distributed_virtual_switch" "vds" {
name = "vDS-Workload-Networks"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
resource "vsphere_distributed_port_group" "pg20" {
name = "dvPG-Guest-VM-1"
distributed_virtual_switch_uuid = data.vsphere_distributed_virtual_switch.vds.id
number_of_ports = 8
vlan_id = 20
}
resource "vsphere_distributed_port_group" "pg21" {
name = "dvPG-Guest-VM-2"
distributed_virtual_switch_uuid = data.vsphere_distributed_virtual_switch.vds.id
number_of_ports = 8
vlan_id = 21
}
resource "vsphere_distributed_port_group" "pg25" {
name = "dvPG-Secure-VM-1"
distributed_virtual_switch_uuid = data.vsphere_distributed_virtual_switch.vds.id
number_of_ports = 8
vlan_id = 25
}
Lets break this down.
First we are specifying which terraform provider we want to use, this will be the vSphere provider in this case. We are then providing some parameters for Terraform to connect to your vCenter instance; VCSA FQDN and credentials.
We then have two ‘data’ blocks. These are used to get information about an existing resource, such as the Distributed Switch and the Datacenter it resides in. You could loosely consider this similar to populating variables in the PowerShell example.
Next we have three ‘resource’ blocks. Each block represents one of the three Port Groups we want to configure. It provides parameters for Name, number of ports and vlan ID for each, along with a reference to the Distributed Switch from the ‘data’ block.
Now when you run ‘terraform apply’ to apply for code, here is the output:
terraform apply
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# vsphere_distributed_port_group.pg20 will be created
+ resource "vsphere_distributed_port_group" "pg20" {
+ active_uplinks = (known after apply)
+ allow_forged_transmits = (known after apply)
+ allow_mac_changes = (known after apply)
+ allow_promiscuous = (known after apply)
+ auto_expand = true
+ block_all_ports = (known after apply)
+ check_beacon = (known after apply)
+ config_version = (known after apply)
+ directpath_gen2_allowed = (known after apply)
+ distributed_virtual_switch_uuid = "50 33 5e 01 05 1e 32 66-ea f7 7c 42 ce fa f1 96"
+ egress_shaping_average_bandwidth = (known after apply)
+ egress_shaping_burst_size = (known after apply)
+ egress_shaping_enabled = (known after apply)
+ egress_shaping_peak_bandwidth = (known after apply)
+ failback = (known after apply)
+ id = (known after apply)
+ ingress_shaping_average_bandwidth = (known after apply)
+ ingress_shaping_burst_size = (known after apply)
+ ingress_shaping_enabled = (known after apply)
+ ingress_shaping_peak_bandwidth = (known after apply)
+ key = (known after apply)
+ lacp_enabled = (known after apply)
+ lacp_mode = (known after apply)
+ name = "dvPG-Guest-VM-1"
+ netflow_enabled = (known after apply)
+ network_resource_pool_key = "-1"
+ notify_switches = (known after apply)
+ number_of_ports = 8
+ port_private_secondary_vlan_id = (known after apply)
+ standby_uplinks = (known after apply)
+ teaming_policy = (known after apply)
+ tx_uplink = (known after apply)
+ type = "earlyBinding"
+ vlan_id = 20
+ vlan_range {
+ max_vlan = (known after apply)
+ min_vlan = (known after apply)
}
}
# vsphere_distributed_port_group.pg21 will be created
+ resource "vsphere_distributed_port_group" "pg21" {
+ active_uplinks = (known after apply)
+ allow_forged_transmits = (known after apply)
+ allow_mac_changes = (known after apply)
+ allow_promiscuous = (known after apply)
+ auto_expand = true
+ block_all_ports = (known after apply)
+ check_beacon = (known after apply)
+ config_version = (known after apply)
+ directpath_gen2_allowed = (known after apply)
+ distributed_virtual_switch_uuid = "50 33 5e 01 05 1e 32 66-ea f7 7c 42 ce fa f1 96"
+ egress_shaping_average_bandwidth = (known after apply)
+ egress_shaping_burst_size = (known after apply)
+ egress_shaping_enabled = (known after apply)
+ egress_shaping_peak_bandwidth = (known after apply)
+ failback = (known after apply)
+ id = (known after apply)
+ ingress_shaping_average_bandwidth = (known after apply)
+ ingress_shaping_burst_size = (known after apply)
+ ingress_shaping_enabled = (known after apply)
+ ingress_shaping_peak_bandwidth = (known after apply)
+ key = (known after apply)
+ lacp_enabled = (known after apply)
+ lacp_mode = (known after apply)
+ name = "dvPG-Guest-VM-2"
+ netflow_enabled = (known after apply)
+ network_resource_pool_key = "-1"
+ notify_switches = (known after apply)
+ number_of_ports = 8
+ port_private_secondary_vlan_id = (known after apply)
+ standby_uplinks = (known after apply)
+ teaming_policy = (known after apply)
+ tx_uplink = (known after apply)
+ type = "earlyBinding"
+ vlan_id = 21
+ vlan_range {
+ max_vlan = (known after apply)
+ min_vlan = (known after apply)
}
}
# vsphere_distributed_port_group.pg25 will be created
+ resource "vsphere_distributed_port_group" "pg25" {
+ active_uplinks = (known after apply)
+ allow_forged_transmits = (known after apply)
+ allow_mac_changes = (known after apply)
+ allow_promiscuous = (known after apply)
+ auto_expand = true
+ block_all_ports = (known after apply)
+ check_beacon = (known after apply)
+ config_version = (known after apply)
+ directpath_gen2_allowed = (known after apply)
+ distributed_virtual_switch_uuid = "50 33 5e 01 05 1e 32 66-ea f7 7c 42 ce fa f1 96"
+ egress_shaping_average_bandwidth = (known after apply)
+ egress_shaping_burst_size = (known after apply)
+ egress_shaping_enabled = (known after apply)
+ egress_shaping_peak_bandwidth = (known after apply)
+ failback = (known after apply)
+ id = (known after apply)
+ ingress_shaping_average_bandwidth = (known after apply)
+ ingress_shaping_burst_size = (known after apply)
+ ingress_shaping_enabled = (known after apply)
+ ingress_shaping_peak_bandwidth = (known after apply)
+ key = (known after apply)
+ lacp_enabled = (known after apply)
+ lacp_mode = (known after apply)
+ name = "dvPG-Secure-VM-1"
+ netflow_enabled = (known after apply)
+ network_resource_pool_key = "-1"
+ notify_switches = (known after apply)
+ number_of_ports = 8
+ port_private_secondary_vlan_id = (known after apply)
+ standby_uplinks = (known after apply)
+ teaming_policy = (known after apply)
+ tx_uplink = (known after apply)
+ type = "earlyBinding"
+ vlan_id = 25
+ vlan_range {
+ max_vlan = (known after apply)
+ min_vlan = (known after apply)
}
}
Plan: 3 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
vsphere_distributed_port_group.pg20: Creating...
vsphere_distributed_port_group.pg21: Creating...
vsphere_distributed_port_group.pg25: Creating...
vsphere_distributed_port_group.pg25: Creation complete after 0s [id=dvportgroup-2669728]
vsphere_distributed_port_group.pg21: Creation complete after 0s [id=dvportgroup-2669730]
vsphere_distributed_port_group.pg20: Creation complete after 0s [id=dvportgroup-2669729]
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
For more information on the vSphere provider from Terraform, check out this link.
You will have noticed that I have explicitly defined the number of ports in both the PowerShell and Terraform examples. This is purely to match up with the default value that is set when using the vSphere Client; 8. By default the port allocation automatically expands as required, so this is for consistency rather than anything else.
If you are someone who relies heavily on a GUI as part of your work, I hope this have given you some idea’s on how you can perhaps leverage other options, especially when looking to build or configure in bulk.
Some time back I wrote about setting up and enabling a HyTrust Key Management setup for vSphere to make use of VM and vSAN encryption. Following the release of vSphere 7.0 Update 2, VMware have introduced native key management capabilities! This is a great feature as you no longer require a potentially expensive separate key management solution to make use of vSphere’s encryption offerings.
Lets take a look at this new capability by heading over to the Key Providers menu on your vCenter object, and selecting ‘Add Native Key Provider’:
Give your provider a name:
It then needs backing up! There is an option to do this next to the ‘Add’ option, or in the flow graphic at the bottom:
It is recommended to protect this with a password, make sure you keep this safe along with the key itself, after it downloads when you hit ‘Back Up Key Provider’. You won’t be able to restore the provider without it should you have a need to. Without the provider, any VM’s or data encrypted with it will be lost.
Once its backed up and safely stored you will have an active KMS! You can choose to set it to default if you have more than one key provider if you wish. Any VM’s that are encrypted from the point of changing the default, will be with the new provider, any already encrypted VM’s will continue to be encrypted with the original key.
If you head over to vSAN services, you will now have your native key provider available and can enable Data-At-Rest encryption as well as Data-In-Transit encryption:
Likewise, if you edit the settings of a VM via the VM Options tab you will be able to enable VM encryption:
There you have it, a native Key Management capability, in built with vSphere 7.0 Update 2.
Having recently had to do some work with RDM perennial reservations I looked into ways to make this less of a manual headache. There are plenty of examples out there for doing this, which I took as a basis to make a PowerShell function. If anything it was a great way to refresh my PowerShell skills and an opportunity to learn some new skills.
Note: Although this has been tested in my environment, please make sure you test it appropriately before running against a production environment!
Lets take a look…
Get-PerennialReservation
This function targets a vSphere cluster, gets all RDM disks that are connected to VM’s and then queries each host in the cluster to check if the disk/storage device is perennially reserved or not.
There are multiple ways to use it, whether that is by specifying the target cluster using the -Cluster parameter or by piping it from Get-Cluster. You can also specify a specific canonical name or a comma separated string of them, if you just want the status of a single/select disk(s) using the -CanonicalName parameter. There is also an Export flag to export the results to CSV, if you wish to make use of the data outside of PowerShell. You can get the full usage information by running the following command once you have loaded the function into your PowerShell session:
This function again targets a vSphere cluster, gets all RDM disks that are connected to VM’s and sets the IsPerenniallyReserved flag too ‘True’ on all hosts.
There are multiple ways to use it like the Get function; specifying the target cluster using the -Cluster paramater or by piping it from Get-Cluster. You can still specify a specific canonical name or a comma separated string of them, if you just want to set the flag of a single/select disk(s) using the -CanonicalName parameter. There is still an Export function that will provide you an output to CSV. You can get the full usage information by running the following command once you have loaded the function into your PowerShell session:
To complete the set there is a Remove function. This function again targets a vSphere cluster, but this time you need to pass in the canonical name you wish to set the IsPerenniallyReserved flag too ‘False’ for.
To use this one, you need to specify the target cluster using the -Cluster paramater and specify a specific canonical name or a comma separated string of them, using the -CanonicalName parameter. There is still an Export function that will provide you an output to CSV. You can get the full usage information by running the following command once you have loaded the function into your PowerShell session:
There are times as a vSphere admin, you are going to want to run ESXCLI commands against multiple ESXi Hosts from a central location. This could be for configuration / administration, reporting, patching or a number of other things.
Recently I have been testing different values in the /DataMover/MaxHWTransferSize advanced setting. To make life easier, I wanted a way to change multiple hosts quickly and easily. To do this, I customised a script that Luc Dekens posted as a solution to a problem someone was having that can be used to send ESXCLI commands to multiple hosts using PowerCLI and plink.exe. This slightly modified version uses a CSV file as a source containing my hosts FQDN and the username and password I will be connecting with.
Plink, which is part of the PuTTy suite, can can be found here.
When using this script, you need to either run the script from a directory containing the plink executable, copy it to where you want to run the script, or adjust the script to include the path to the plink executable… whichever takes your fancy.
Disclaimer: Always complete your own testing in an appropriate environment and refer to the vendors official documentation!
$Hosts = Import-Csv C:\ESXiHosts.csv
$Commad = 'esxcfg-advcfg -s 16384 /DataMover/MaxHWTransferSize'
Foreach ($H in $Hosts) {
#Starting the SSH Service if not already started
$SSHService = Get-VMHostService -VMHost $H.HostName | where {$_.Key -eq 'TSM-SSH'}
if ($SSHService.Running -eq 'True') {
Write-Host "****************************" -ForegroundColor Blue
Write-Host "WARNING: SSH already enabled, this will be stopped on completion of this script" -ForegroundColor Yellow
}
Else {
Write-Host "Starting SSH Service on Host $($H.HostName)" -ForegroundColor Green
Start-VMHostService -HostService $SSHService -Confirm:$false > $null
}
#Running the defined ESXCLI Command(s)
Write-host "Running remote SSH commands on $($H.HostName)." -ForegroundColor Green
Echo Y | ./plink.exe $H.HostName -pw $H.Password -l $H.UserName $Commad
#Stopping the SSH Service
$SSHService = Get-VMHostService -VMHost $H.HostName | where {$_.Key -eq 'TSM-SSH'}
if ($SSHService.Running) {
Write-Host "Stopping SSH Service on Host $($H.HostName)" -ForegroundColor Green
Stop-VMHostService -HostService $SSHService -Confirm:$false > $null
Write-Host "****************************" -ForegroundColor Blue
}
}
Write-Host "Complete $(Get-Date)" -ForegroundColor Green
You can run as many commands as you need by declaring another ‘Command’ variable at the beginning of the script and adding another line to the ‘Running the defined ESXCLI Command(s)’ section.
When run, it will then cycle through each of the ESXi hosts from your CSV file, enable SSH (if its not already enabled), accept the host key, run the commands you have specified and finally turn the SSH service off.
Here you can see it has set the MaxHWTransferSize to 16384 on each host.
You will see the Recent Task pane show the SSH Service starts and stops.
The commands passed in can be anything you need. All you need to do is change the commands that are defined in the variables section. For example, restarting the management agents –
Recently I decided it was time to add a second vCenter 7.0 Appliance to my main lab environment after the lab containing my SRM and vSphere Replication installation ceased to exist…
I thought I would take the CLI route as its been a while, and thought I’d share!
To begin, you need to decide what you are deploying. There are four deployment options available to you, which you can see listed below. To see the options, mount the vCenter ISO image, browse to vcsa-cli-installer\templates\install, and you will find 4 templates;
Embedded on ESXi
Embedded on VC
Embedded replication on ESXi
Embedded replication on VC.
Note there is not a distributed option here anymore as this is depreciated in 7.0.
For my lab I will be using the 3rd option; ‘Embedded replication on ESXi’. Firstly because I’m deploying to a standalone host and not to an existing vCenter. Secondly as I already have an existing VCSA and SSO Domain. This new VCSA will be added, or linked to the existing VCSA for my ‘Recovery’ site, in my Site Recovery Manager (SRM) setup.
If you are looking to deploy your first VCSA, onto a standalone host, you will want to use the ‘Embedded on ESXi’ template.
Once you have decided on the template that suits your scenario, you are going to add some details to this template, such as the ESXi host information you are deploying to, networking information, NTP and in my case SSO details as I will be adding it to an existing SSO Domain. One important value is the deployment size (deployment_option in the example below).
A useful command that can be run to help you decide what size appliance is suitable for your needs is:
vcsa-deploy --supported-deployment-sizes
This outputs the vCenter sizing to assist you. It shows you the resource requirements as well as the amount of hosts and VM’s each can support.
For my lab, ‘tiny’ covers my needs.
Here is the json file I used for the deployment in my lab. I have excluded the passwords for obvious reason, but it can be ran like this, and will prompt you for the passwords in the terminal.
{
    "__version": "2.13.0",
    "__comments": "Sample template to deploy a vCenter Server Appliance with an embedded Platform Services Controller as a replication partner to another embedded vCenter Server Appliance, on an ESXi host.",
    "new_vcsa": {
        "esxi": {
            "hostname": "smt-lab-esx-04.smt-lab.local",
            "username": "root",
            "password": "",
            "deployment_network": "vSS_PG_Management",
            "datastore": "smt-lab-vmfs-02a"
        },
        "appliance": {
            "__comments": [
                "You must provide the 'deployment_option' key with a value, which will affect the VCSA's configuration parameters, such as the VCSA's number of vCPUs, the memory size, the storage size, and the maximum numbers of ESXi hosts and VMs which can be managed. For a list of acceptable values, run the supported deployment sizes help, i.e. vcsa-deploy --supported-deployment-sizes"
            ],
            "thin_disk_mode": true,
            "deployment_option": "tiny",
            "name": "smt-lab-vcsa-02"
        },
        "network": {
            "ip_family": "ipv4",
            "mode": "static",
            "system_name": "smt-lab-vcsa-02.smt-lab.local",
            "ip": "10.200.15.249",
            "prefix": "24",
            "gateway": "10.200.15.254",
            "dns_servers": [
                "10.200.15.10"
            ]
        },
        "os": {
            "password": "",
            "ntp_servers": "0.uk.pool.ntp.org",
            "ssh_enable": true
        },
        "sso": {
            "password": "",
            "domain_name": "vsphere.local",
            "first_instance": false,
            "replication_partner_hostname": "smt-lab-vcsa-01.smt-lab.local",
            "sso_port": 443
        }
    },
    "ceip": {
        "description": {
            "__comments": [
                "++++VMware Customer Experience Improvement Program (CEIP)++++",
                "VMware's Customer Experience Improvement Program (CEIP) ",
                "provides VMware with information that enables VMware to ",
                "improve its products and services, to fix problems, ",
                "and to advise you on how best to deploy and use our ",
                "products. As part of CEIP, VMware collects technical ",
                "information about your organization's use of VMware ",
                "products and services on a regular basis in association ",
                "with your organization's VMware license key(s). This ",
                "information does not personally identify any individual. ",
                "",
                "Additional information regarding the data collected ",
                "through CEIP and the purposes for which it is used by ",
                "VMware is set forth in the Trust & Assurance Center at ",
                "http://www.vmware.com/trustvmware/ceip.html . If you ",
                "prefer not to participate in VMware's CEIP for this ",
                "product, you should disable CEIP by setting ",
                "'ceip_enabled': false. You may join or leave VMware's ",
                "CEIP for this product at any time. Please confirm your ",
                "acknowledgement by passing in the parameter ",
                "--acknowledge-ceip in the command line.",
                "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
            ]
        },
        "settings": {
            "ceip_enabled": true
        }
    }
}
Once you have prepared your file, there are a couple of commands you can run from a PowerShell prompt to validate your configuration before deploying, saving you some time should mistakes have been made. The first being:
.\vcsa-deploy.exe install --accept-eula --acknowledge-ceip --verify-template-only <Path to json File>
This completes some basic checks to ensure your json file is correct, here is a successful output:
Secondly:
.\vcsa-deploy.exe install --accept-eula --acknowledge-ceip --precheck-only <Path to json File>
This will perform a more in depth validation, checking things like the credentials for your SSO domain, DNS or whether the IP or name you plan to use for your VCSA is in use already.
Note: Make sure you have your DNS setup correctly and is resolving the appliance FQDN!
It will also provide warnings if it thinks you might not be using an appropriate template. I originally specified a host what was already managed by vCenter, so it warned me like so:
You will get a similar output to the first command, should you pass all the tests. If not you will need to look at resolving them to ensure you get a successful deployment.
The Install!
Once you are confident you have everything in place, including DNS, and your configuration files are correct, you are ready to install:
.\vcsa-deploy.exe install --accept-eula --acknowledge-ceip --no-ssl-certificate-verification <Path to json File>
Here is a cut down version of the output you will see during the deployment:
====== [START] Start executing Task: To validate CLI options at 12:46:25 ======
Command line arguments verfied.
[SUCCEEDED] Successfully executed Task 'CLIOptionsValidationTask: Executing CLI
optionsValidation task' in TaskFlow 'template_validation' at 12:46:26
[START] Start executing Task: To validate the syntax of the template. at
12:46:27
Template syntax validation for template
'M:\Software\VMware\vCenter\embedded_vCSA_replication_on_ESXi.json' succeeded.
Syntax validation for all templates succeeded.
====== [START] Start executing Task: Perform precheck tasks. at 12:46:39 ======
[START] Start executing Task: Verify that the provided credentials for the
target ESXi/VC are valid at 12:46:45
The certificate of server 'smt-lab-esx-04.smt-lab.local' will not be verified
because you have provided either the '--no-ssl-certificate-verification' or
'--no-esx-ssl-verify' command parameter, which disables verification for all
certificates. Remove this parameter from the command line if you want server
certificates to be verified.
================== [START] Start executing Task: at 12:47:47 ==================
= [SUCCEEDED] Successfully executed Task '' in TaskFlow 'install' at 12:47:47 =
[START] Start executing Task: Check whether the datastore's free space
accommodate the VCSA's deployment option at 12:47:51
[SUCCEEDED] Successfully executed Task 'Running precheck: TargetDsFreespace' in
TaskFlow 'install' at 12:47:51
==========VCSA Deployment Progress Report========== Task: Install
required RPMs for the appliance.(RUNNING 5/100) - Setting up storage
VCSA Deployment is still running
==========VCSA Deployment Progress Report========== Task: Install
required RPMs for the appliance.(SUCCEEDED 100/100) - Task has completed
successfully. Task: Run firstboot scripts.(SUCCEEDED 100/100) - Task has
completed successfully.
Successfully completed VCSA deployment. VCSA Deployment Start Time:
2020-12-28T13:19:19.291Z VCSA Deployment End Time: 2020-12-28T14:18:27.103Z
[SUCCEEDED] Successfully executed Task 'MonitorDeploymentTask: Monitoring
Deployment' in TaskFlow 'embedded_vCSA_replication_on_ESXi' at 14:18:45
Monitoring VCSA Deploy task completed
The certificate of server 'smt-lab-vcsa-02.smt-lab.local' will not be verified
because you have provided either the '--no-ssl-certificate-verification' or
'--no-esx-ssl-verify' command parameter, which disables verification for all
certificates. Remove this parameter from the command line if you want server
certificates to be verified.
== [START] Start executing Task: Join active domain if necessary at 14:18:59 ==
Domain join task not applicable, skipping task
[SUCCEEDED] Successfully executed Task 'Running deployment: Domain Join' in
TaskFlow 'embedded_vCSA_replication_on_ESXi' at 14:18:59
[START] Start executing Task: Provide the login information about new
appliance. at 14:19:10
Appliance Name: smt-lab-vcsa-02
System Name: smt-lab-vcsa-02.smt-lab.local
System IP: 10.200.15.249
Log in as: Administrator@vsphere.local
[SUCCEEDED] Successfully executed Task 'ApplianceLoginSummaryTask: Provide
appliance login information.' in TaskFlow 'embedded_vCSA_replication_on_ESXi' at
14:19:10
=================================== 14:19:16 ===================================
Once complete, you will now have a second vCenter appliance deployed in Linked mode with the original. Here it is once I had configured a datacenter and cluster with two hosts.
Tags are a really useful component in VMware. They can be used for all manor of things, whether it’s for storage policies, backups, identifying a group of objects or in the case of this post, managing permissions.
Having a method of easily assigning permissions to singular or multiple objects in vCenter can be a great benefit to a vSphere Admin as it’s gives them greater control over the environment they manage.
Lets take a look at what is needed to get this setup:
Script
Tag Category & Tags for each support role.
AD Security Groups
AD Service Account
vCenter Roles (one for the service account, then one for each of the support roles)
PowerCLI VICredentials
Scheduled Task
In this example I will use 4 common support teams that could be used, DBA, EUC, Operations and Storage. These can be anything you have a requirement for.
Script
Here is the script that applies the permissions based on the assigned tags. It can also be found here on GitHub. Save this on your management server of choice, or wherever you intend to run the scheduled task as a .PS1 file. In this example it’s saved on a management server in C:\Scripts\VI_Permissions.ps1.
Now onto Tag Categories and Tags in vCenter. Create a Tag category called ‘Support _Teams’ (Or something of your choosing, just make sure you are consistent throughout):
Or using PowerShell – New-TagCategory -Name Support_Teams -Cardinality Multiple -EntityType All
You can select as many object types as you wish and you will also want to allow multiple tags per object.
Now create a tag for each of the support teams in the tag category you just created:
Now for some corresponding AD Security Group for each role you wish to have:
Service Account (AD User)
Now to create an AD user account that will be used to apply the permissions within vCenter. This will be the account that will be used to run the scheduled task, connect to vCenter and will have the appropriate permissions to assign permissions for the support roles.
Support Team Roles
Now we need to create a suitable role for each team. In this example I have copied the Virtual Machine Power User role, but these roles can contain which ever privilege’s you require.
Under ‘Administration > Roles’ you will see the options to either create a new Role or copy an existing. From here you will be able to assign it a name and specify the privilege’s you require.
You will be referencing these Role names in the script so make sure you continue to match the names thought the process.
Permissioning Role
As mentioned in the service account section, the account (tag_permissions) running the scheduled task will need permissions in vCenter through a role. The privileges this role will hold, needs to include all the privilege’s that are referenced in all of your Support Team Roles in order for it to have the right to assign the permissions. For example, if all your support roles are a copy of the ‘Virtual Machine power user’ role, your tagging permissions role will need to contain the same privileges.
Depending on how broad the scope of your support team roles, you may want to use the ‘Administrator’ or the ‘No cryptography administrator’ role. This is entirely up to you and how you manage your estate.
For this example in my lab, I will use the predefined ‘Administrator’ role to grant the ‘tag_permissions’ AD account permissions at the Global Root, ensuring you have selected the ‘Propagate to children’ option.
You could create a copy of the ‘Administrator’ role and name it something like ‘VI Permissions Service’ for instance, to give you flexibility to modify it in the future as well as making it easy to identify. With any high privileged account, ensure you secure it appropriately.
Create VI Credential Item
Now to create an encrypted credentials file that the service account running the scheduled task can import and then use to connect to vCenter without any intervention.
The AD account that is used to run the scheduled task, must be the account that also creates the credentials file as this is the only user that can use it. It will require permissions to run PowerShell and have access to a folder location to store the credentials file on your chosen management server.
To begin, start a PowerShell session in the context of the service account:
Note: Ensure the server that you are running this scheduled task from has PowerCLI installed. Installing PowerCLI.
Then run the following, entering your vCenter FQDN and the user and password that you created:
Ensure you are storing the file somewhere with appropriate access to allow this but, also to restrict any unnecessary access. The credentials file can have the password read if the user account that created it is compromised and gains access to the file using those windows credentials.
Scheduled Task
Now for the last component, the scheduled task. On a management server or a server of your choosing, create a scheduled task:
Assign an appropriate schedule that suits the level of change and size of your environment:
Now configure the trigger to execute the script:
Now thats everything you need to set this up, so lets give it a run though!
Assigning Tags and Permissions
Lets take a look at my demo VM permissions before we begin assigning permissions:
Lets check the VM permissions before having any tags assigned:
Now you can either manually run the scheduled task or wait until its next scheduled run time. Once the job has run, you can now check the tags match the permissions assigned by running the following:
Finally, if you want to know which objects are supported by a specific team and have access you can check this by running:
Get-TagAssignment | Where {$_.Tag -like "Support_Teams/DBA_Team"}
You now have a way of assigning and removing permissions from vCenter objects using Tags. In this example I have used virtual machine object, but depending on your requirements, and the scope you set on the tag category, you could use this for other vCenter objects.
IT security, accountability and auditability are critical today. Securing vCenter Server using auditable identities, for instance via an Active Directory identity source, is likely common for most vCenter consumers. This ensures individual access can be used to audit actions back to an admin as well as provide higher security through strong password policies and the absence of a shared account credentials, such as the SSO administrator.
Something that can be overlooked is the security of the ESXi hosts themselves.
There are multiple options for securing your ESXi hosts, one being the use of lockdown modes and limited user access, restricted management network access, or a combination of them both.
In this blog post I want to show you a simple way to configure your hosts to use an Active Directory group to control user access to an ESXi host.
This is achieved by editing the value associated with an advanced setting – ‘Config.HostAgent.plugins.hostsvc.esxAdminsGroup’.
One prerequisite to achieving this is that the hosts must be domain joined. Information on how to do this can be found here.
Editing this on a handful of servers is easy enough if you are doing it manually, but who wants to be manually typing or copying & pasting this?
I have put together a PowerShell Function that can simplify the editing of this setting for single hosts, or on mass to all ESXi hosts that you have connected your PowerCLI session to.
Set-ESXiHostAdminGroup -Target single -Entity esxi01 -Group "infrastructure_admins"
Set-ESXiHostAdminGroup -Target all -Group "infrastructure_admins"
For the purposes of this demo, I will update all ESXi Hosts within my vCenter instance using the second example. You could edit the function to target clusters if you wish.
Setting before –
Set-ESXiHostAdminGroup -Target all -Group "infrastructure_admins"
Function Output
After –
You will need to wait the length of time defined in this setting until being able to log in –
Now all users that are in the ‘infrastructure_admins’ Active Directory group will be able to log into the ESXi host with administrator permissions using their AD credentials.