• Chapter 2: Automating vSphere Hypervisor Deployment and Configuration
• Chapter 3: Automating Networking
• Chapter 4: Automating Storage
• Chapter 5: Using Advanced vSphere Features
Chapter 1
Automating vCenter Server Deployment and Configuration
In this chapter, you will learn to:
• Prepare the vCenter Installation
• Create an Automated Installation
• Set Up Your vCenter Server Folder Structure
• Creating a Folder Structure from Scratch
• Exporting a Folder Structure
• Importing a Folder Structure
• Define Users and Their Privileges
• Granting Privileges
• Creating New Roles
• Bringing In Users
• Exporting Permissions
• Importing Permissions
• Configure Datacenters and Clusters
• Creating Datacenters
• Creating Clusters
• Configuring High Availability
• Configuring Distributed Resource Scheduler
• Configuring Enhanced vMotion Compatibility
• Configuring Distributed Power Management
• Licensing
• Viewing License Information
• Licensing a Host
One of the focal points and key use cases of PowerCLI is the automation of tasks that are needed either as part of a disaster recovery (DR) solution or as part of an automated deployment solution that can be used repeatedly – you’ll be safe in the knowledge that scripts will produce consistent and easy-to-use solutions.
This chapter will take you through some common areas automated within vSphere, starting at the beginning of the virtual infrastructure. Not only will we show you how to automate the build, but we’ll also provide examples of export scripts that will help you export information into a centralized area. The exported data will then be ready for use in reports or for the import process of another setup.
Prepare the vCenter Installation
As part of the overall virtual infrastructure, one of the first products you will need to install is the vCenter Server, or Virtual Infrastructure Server. Although this cannot be done directly using PowerCLI cmdlets, you can use the automated nature of PowerCLI and PowerShell to automate the vCenter Server installation.
The key thing to remember while reading this chapter – and indeed the entire book – is that PowerShell reaches past the virtual infrastructure. It can be used to manage most areas of the Windows-based operating system and application set. PowerCLI is purely an addition to PowerShell that allows you to manage the virtual infrastructure.
To automate the installation of vCenter Server and its respective components, including the vSphere Client, Update Manager, Converter, and the corresponding databases, you will need the install media as well as various other items, such as the correct version of the .NET Framework and Windows installed on the server. The components you choose to install will depend on your infrastructure and the type of database you are going to use with your vCenter Server install.
Before you attempt to create an automated installation, be sure that:
• The server meets at least the minimum hardware requirements as specified in the VMware ESX and vCenter Server installation documents provided by VMware.
• The server is configured with a static IP address.
• The computer name consists of fewer than 15 characters. (To conform to best practice, ensure that the computer name matches the hostname in the fully qualified domain name [FQDN] of the system.)
• The system is joined to a domain, and not a workgroup. Although this is not a strict requirement, domain membership ensures that when you’re using advanced features like the vCenter Guided Consolidation Service, the vCenter Server will be able to find all domains and systems on the network for the purpose of converting physical systems to virtual machines (VMs).
• The service user account that will be used for installation is added to the Log On As A Service policy.
• A supported database is already available unless you plan on using the internal vPostgres database.
• A valid system data source name (DSN) exists that allows vCenter Server to connect to the created database.
• The vCenter Server is able to directly access the hosts it will manage without any network address translation between the server and the hosts.
No Magic Wands
Notice that all these requirements and recommendations are the same as those you’d check if you were manually installing vCenter Server on a single machine. People often think that scripting introduces some kind of magic or new ways to do things behind the scene. Not so! We use exactly the same methods VMware does for a manual install; it’s just automated. If things go wrong, troubleshoot them the same way you would for a standard vCenter Server install that went wrong.
Create an Automated Installation
When installing vCenter Server manually, you first download the media, and then run through a series of wizards, ensuring that each step within the wizard is correctly configured before completing the installation and waiting for the wizard to install vCenter Server. This process can become cumbersome if the installation needs to be repeated multiple times, and mistakes can be made that could cause key configured items to be incorrect.
Once you know what properties are required to perform an automated (also known as silent) install, you will be able to begin writing a script that can be reused as many times as desired. One key to creating a successful installation script that can be reused is to use variables for property values. This allows the user to use CSV files, additional scripts, and other methods to specify different values for each property in subsequent deployments without having to manually edit the installation script.
Generally, scripts have a few key items: property variables for repeatability, the location of the installation media, installer switches that specify how the installer will act, and a line that creates the installation string to be run.
The automated vCenter installation scripts vary slightly depending on the version of vCenter used (requirements and features can change between versions). The properties defined in Listing 1-1 are configured for use with vCenter Server 6. If you are using a previous version of vCenter Server for your install, the properties may be different. However, the method of invoking the vCenter installation remains the same.
In this example, we are installing vCenter Server 6 using a remote SQL Server 2014 database. vCenter Server 6 can also install using an internal vPostgres database. To ensure a successful installation, we specify values for all of the properties required for the type of installation we are performing.
NOTE A manual install offers multiple installation paths and options. When performing an automated install, use only the inputs necessary for the type of deploy you want to perform. There is no need to specify every single available property within the installer GUI.
As you can see in Listing 1-1, once values have been given to each of the variables for the required properties, it is only a matter of creating the argument string that will be passed to the installer. Using a script like this ensures each installation is configured correctly and no mistakes are made.
Before