My previous post introduced Salt Extension Modules for VMware, this is an open source project that provides a collection of Salt-maintained extension modules for VMware vSphere, vCenter, ESXi, NSX-T, VMC and friends. That post covered also commands. In this post we will cover State files.
At the time I am writing this post there aren’t a lot State Modules, however those currently available are a great starting point and more importantly the list is growing fast with every release!
This post is a follow up on my introductory post about SDDC Modules that guides you to install these modules, connect to your vCenter. From this we can proceed creating our first State file. We will starting with something that isn’t harmful: vCenter VM Folder management. Next post will be more interesting as I’ll cover VMware Cloud on AWS (VMC) security configurations.
~/salt/srv/salt/folder_manage.sls State file with the following content:
create_folder: vmware_folder.manage: - name: sddc_extensions - task: create - dc_name: 'Region A' - type: vm
Here we are using State Module
vmware_folder which come with
move functions. In this case we are using
manage that creates or destroys a folder and requires the following parameters:
name: the name of the folder
dc_name: the name of the datacenter where the folder will be created (or deleted)
type: the type of the folder to be created, possible options are:
vm, host, datastoreand
So, with the State file above we can create a new Virtual Machine folder named “sddc_extensions” in the Datacenter named “Region A”. Let’s do it:
salt-call state.apply folder_manage
In order to remove the newly created folder we could reuse the same state file only changing
destroy. But let’s try something different. I stated before that currently there aren’t many State Modules, however we have a good number of Execution Modules functionalities. Thus, we can use the
module.run capability that allows individual Execution Module call from State files, you can get deeper on this approach here.
~/salt/srv/salt/folder_destroy.sls with the following content:
destroy_folder: module.run: - name: vmware_folder.destroy - folder_name: sddc_extensions - dc_name: 'Region A' - type: vm
In this State file we are calling the
destroy function from the
vmware_folder Execution Module passing the required parameters (
salt-call state.apply folder_destroy
That’s it for today. Next post will cover some more compelling security for VMC use case.