Automation is all the rage when it comes to provisioning, configuring, and testing infrastructure these days. There are simply too many moving parts to manually configure tens, hundreds, or even thousands of servers by hand.

With virtualization, server environments have exploded and infrastructure engineers find themselves looking for ways of automating bulk configuration changes to virtual machines and how this can be accomplished with tools readily available today. Infrastructure today is configured much like code. By utilizing scripting and automation framework tools, engineers can effectively automate mass changes to virtual machines in their environments.

Protect Your Data with BDRSuite

Cost-Effective Backup Solution for VMs, Servers, Endpoints, Cloud VMs & SaaS applications. Supports On-Premise, Remote, Hybrid and Cloud Backup, including Disaster Recovery, Ransomware Defense & more!

Let’s see how we can automate bulk virtual machine configuration changes both from a VMware perspective as well as through Windows.

Why Automation?

Why do we care about automation? As mentioned in the outset, today’s virtualized infrastructure systems are simply too complicated and have too many configurational pieces that must be updated, often in bulk. It is simply impossible for a human or even a group of humans to manually make those configuration changes by hand. Automation allows introducing a system of automated changes that are dictated by human intervention that changes and configuration parameters can be synchronized with a group of resources with the “push of a button”.

Download Banner

Additionally, configuration management and configuration drift is something that organizations want to ensure in environments today. With the multitude of virtual machines that often exist in today’s environments and a number of administrators that have access to certain VMs, there exists the chance of configurations getting skewed from the designated configuration at the time of provisioning. Having an automated way to align virtual machines with a “desired state” is a great way to ensure that virtual machines are always in line with the intended configuration at the time of deployment. Manually making checks and correcting any deviation from a desired state again would be very labor intensive and problematic from a human error standpoint.

Often compliance regulations such as PCI and others want organizations to be able to show they have a system in place to ensure that configurational changes are controlled and automated to ensure that production systems are always in line with the configuration parameters defined by the regulatory compliance that is to be enforced.

Automated Tools for Bulk Virtual Machine Configuration

As expressed, automated configuration in today’s environments is a necessity due to complexity, compliance, and other requirements that may be specific to a certain organization’s needs. What tools are available to help virtual administrators carry out bulk automation of configuration changes for virtual machines in their environments?

PowerCLI for Automation

For VMware administrators, PowerCLI provides many powerful capabilities that allow automating bulk changes across the VMware vCenter environment. This includes creating, deleting, modifying, and provisioning virtual machines across any number of hosts, clusters, or datacenters. Administrators can make bulk changes to the underlying virtual machine virtual hardware such as memory changes, disk changes, as well as network changes, quickly affecting various virtual machine configuration parameters.

Below are a few configuration examples that you can perform on virtual machines using PowerCLI that allow making bulk configuration changes.

Controlling attached media to virtual machines:

  • Get-VM | Get-CDDrive | where { $_.IsoPath -or $_.HostDevice -or $_.RemoteDevice } | Set-CDDrive -NoMedia -Confirm:$false
  • Get-VM | Get-FloppyDrive | where-object {$_.HostDevice -ne $null} | set-floppydrive -nomedia -Confirm:$false

Finding VMs with an old version of VMware Tools

  • Get-VM | Where-Object {$_.ExtensionData.Guest.ToolsStatus -eq “toolsOld”}

Mass adding virtual disks to a list of virtual machines

  • $vms = Get-Content c:\vms.txt

foreach ($vm in $vms){
Get-VM $vm | New-HardDisk -CapacityGB 300 | New-ScsiController -Type ParaVirtual
Get-VM $vm | New-HardDisk -CapacityGB 500 | New-ScsiController -Type ParaVirtual
Get-VM $vm | New-HardDisk -CapacityGB 500 | New-ScsiController -Type ParaVirtual
}

Using Ansible to Make Bulk Configuration Changes

Ansible is another wildly popular automation framework that allows organizations to quickly and easily automate both provisioning virtual machine as well as making changes in bulk to guest operating systems. It is built on top of Python and utilizes a very human readable language format called YAML that allows coding in a very understandable way.

The example below clones a VM from template:

– name: Create a VM from a template
vmware_guest:
hostname: 192.0.2.44
username: administrator@vsphere.local
password: vmware
validate_certs: no
folder: /testvms
name: testvm_2
state: poweredon
template: template_el7
disk:
– size_gb: 10
type: thin
datastore: g73_datastore
hardware:
memory_mb: 512
num_cpus: 6
num_cpu_cores_per_socket: 3
scsi: paravirtual
memory_reservation: 512
memory_reservation_lock: True
mem_limit: 8096
mem_reservation: 4096
cpu_limit: 8096
cpu_reservation: 4096
max_connections: 5
hotadd_cpu: True
hotremove_cpu: True
hotadd_memory: False
cdrom:
type: iso
iso_path: “

[datastore1] livecd.iso”
networks:
– name: VM Network
mac: aa:bb:dd:aa:00:14
wait_for_ip_address: yes
delegate_to: localhost
register: deploy

Also, handling configuration of Windows servers is very easy with the powerful Windows modules that allow easily interacting with Windows via WinRM. Such configuration as software installation, network configuration, directory creation, file copies, registry changes, etc, are all possible with Ansible.

Below is a code snippet from Ansible to show how easy it is to use Ansible along with Chocolatey to install software on a Windows host.

# install/uninstall with chocolatey
– name: ensure 7-Zip is installed via Chocolatey
win_chocolatey:
name: 7zip
state: present

– name: ensure 7-Zip is not installed via Chocolatey
win_chocolatey:
name: 7zip
state: absent

Chef – Mature Automation Framework

One of the older and more mature products available is Chef. Chef is built on top of Ruby on Rails and also allows configuring Linux and Windows hosts to automate bulk changes. Playing on the “food” analogy all the way through the Chef ecosystem, “recipes” and “cookbooks” are used to make configuration changes to managed systems. It is a little more difficult to get up and running with than Ansible but being a more mature platform, there is often better documentation and such for various automation, configuration, and other tasks you want to accomplish. Additionally, there are literally myriads of available cookbooks for download via the Chef “Supermarket”.

Chef utilizes a client that is installed on the hosts to interact with the control server to provide powerful interaction and abilities as an administrator to control configuration and other items.

Below are example of adding Windows Features to a Windows host using Chef code:

powershell_script ‘Telnet-Client’ do
code ‘Add-WindowsFeature telnet-client’
guard_interpreter :powershell_script
not_if “(Get-WindowsFeature -Name telnet-client).Installed”
end

powershell_script ‘.NET’ do
code ‘Add-WindowsFeature NET-Framework-Features’
guard_interpreter :powershell_script
not_if “(Get-WindowsFeature -Name NET-Framework-Features).Installed”
end

Chef also provides a robust way of interacting with VMware environments. This includes provisioning virtual machines. Below is a simple line of Chef code to provision an Ubuntu virtual machine.

knife esx vm create –vm-name server1 –use-template ubuntu-12.10-x64_template –verbose true –distro ubuntu12.04-19-gems –vm-memory 2048 -x provision -i ~/.ssh/id_rsa

Takeaways

Automating bulk virtual machine configuration changes is a necessary part of today’s modern infrastructure. With the explosion of virtual machines and virtual infrastructure, engineers today must manage infrastructure as code to be both effective and efficient in performing management and configuration tasks. There are many tools that can be utilized by administrators today for automation frameworks. VMware’s PowerCLI is a great way to manage native VMware environments. Now that it is cross-platform with PowerShell Core, it is a great tool to use no matter what platform you are managing from. Ansible and Chef are both great Linux based management platforms that allow quickly and easily making bulk configuration changes and provisioning virtual resources. The DevOps movement has certainly yielded great tools that system administrators and engineers can take advantage of in the quest to efficiently manage today’s production and development infrastructure.

Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.

Rate this post