Learn how to manage vSphere environments with SaltStack

The SaltStack management tool allows admins to create a consistent management system for multiple operating systems, including VMware vSphere environments.

Many corporate networks consist of a mixture of physical and virtual machines. Deploying and managing these machines...

requires a consistent management system. SaltStack is emerging as a tool that offers an alternative to offerings such as Puppet, Ansible and Chef. In this article, we'll discuss how it can be used to manage vSphere environments.

SaltStack provides the means to manage state on target systems, the so-called minions. Any configuration can be managed and applied to remote systems SaltStack through the use of efficient remote execution engines. Although it was designed primarily for the Linux platform, SaltStack can manage other operating systems as well, including VMware vSphere environments.

How SaltStack works

Using SaltStack to manage vSphere environments allows administrators to develop a generic deployment and management strategy that can be applied to physical as well as virtual assets.

SaltStack functions on a minion and master topology. SaltStack works with specific commands that can be executed on one or more minions. To make this happen,  the minion key is imported on the Salt Master, at which point the Salt Master administrator can issue commands like salt '*' 'ls -l /'. This command runs the ls -l / command on all minions currently known to the Salt Master.

Apart from running remote commands, SaltStack allows administrators to use grains. A grain makes it possible to run remote queries on SaltStack minions, thus collecting status information about the minions and allowing administrators to store that information in a central location. Among the many features that are offered, SaltStack can also work with states, which help administrators define a desired state on a target system. These states are applied by using .sls files, which contain very specific instructions about what should happen on a system to obtain a desired state.

Because of the flexibility it offers in managing remote systems, SaltStack-based products are rapidly gaining interest. The functionality can be compared to features that are offered by state management systems such as Puppet and Ansible. SaltStack takes thing a step further and owes its rapid adoption rates to the fact that it includes an efficient way to run remote commands on management systems.

Using SaltStack to manage vSphere

SaltStack can also manage vSphere environments, but the VMware cloud module needs to be configured . This module contains the URL to the vSphere server, as well as a username and password needed to connect to VMware. The /etc/salt/cloud.providers file on the Salt Master is the typical location where this information is stored. Listing 1, shown below, shows sample contents of this file, which allows the Salt Master to interact with target VMware systems.

Listing 1: VMware Cloud Provider Configuration examples

   driver: vmware
   user: 'DOMAIN\user'
   password: 'password'
   url: ''

   driver: vmware
   user: 'DOMAIN\user'
   password: 'password'
   url: ''
   protocol: 'https'
   port: 443

   driver: vmware
   user: 'DOMAIN\user'
   password: 'password'
   url: ''
   protocol: 'http'
   port: 80

   driver: vmware
   user: 'admin'
   password: 'password'
   url: ''

Listing 2: Example SaltStack profile

  provider: vcenter01
  clonefrom: test-vm

  ## Optional arguments
  num_cpus: 4
  : 8GB
      CD/DVD drive 1:
        device_type: datastore_iso_file
        iso_path: "[nap004-1] vmimages/tools-isoimages/linux.iso"
      CD/DVD drive 2:
        device_type: client_device
        mode: atapi
        controller: IDE 2
      CD/DVD drive 3:
        device_type: client_device
        mode: passthrough
        controller: IDE 3
      Hard disk 1:
        size: 30
      Hard disk 2:
        size: 20
        controller: SCSI controller 2
      Hard disk 3:
        size: 5
        controller: SCSI controller 3
      Network adapter 1:
        name: 10.20.30-400-Test
        switch_type: standard
        gateway: []
      Network adapter 2:
        name: 10.30.40-500-Dev-DHCP
        adapter_type: e1000
        switch_type: distributed
      Network adapter 3:
        name: 10.40.50-600-Prod
        adapter_type: vmxnet3
        switch_type: distributed
        gateway: []
      SCSI controller 1:
        type: lsilogic
      SCSI controller 2:
        type: lsilogic_sas
        bus_sharing: virtual
      SCSI controller 3:
        type: paravirtual
        bus_sharing: physical
      IDE 2
      IDE 3


  resourcepool: Resources
  cluster: Prod

  datastore: HUGE-DATASTORE-Cluster
  folder: Development
  datacenter: DC1
  template: False
  power_on: True
     mem.hotadd: 'yes' bar
    guestinfo.customVariable: customValue

  deploy: True
  customization: True
  private_key: /root/.ssh/mykey.pem
  ssh_username: cloud-user
  password: veryVeryBadPassword

    /path/to/local/custom/script: /path/to/remote/script
    /path/to/local/file: /path/to/remote/file
    /srv/salt/yum/epel.repo: /etc/yum.repos.d/epel.repo

  hardware_version: 10
  image: centos64Guest

Once the connection to the vSphere environment has been defined, SaltStack can talk directly to the vSphere server and perform automated operations, such as starting VMs. In order to do so, a profile needs to be defined. Listing 2, shown below, offers an example of such a profile.

Once the profile has been defined, it needs to be applied. As a salt cloud module is used to interface with the vSphere infrastructure, you should use the salt-cloud command to do so. The generic structure of this command is salt-cloud -p myprofile myinstance. This command applies a profile as shown in Listing 2 to deploy an instance with the name myinstance.

Using SaltStack to manage vSphere environments allows administrators to develop a generic deployment and management strategy that can be applied to physical as well as virtual assets.

Next Steps

Is there room for configuration management tools alongside containers?

Tips for nailing your cloud administrator interview

Why is building the right configuration management system so critical?

Migrating data and apps in a hybrid cloud environment

Dig Deeper on VMware basics