{"id":1632,"date":"2022-01-24T17:18:10","date_gmt":"2022-01-24T16:18:10","guid":{"rendered":"https:\/\/nine30.info\/?p=1632"},"modified":"2022-01-24T17:18:10","modified_gmt":"2022-01-24T16:18:10","slug":"salt-sddc-modules-state-files","status":"publish","type":"post","link":"https:\/\/nine30.nxt70.com\/index.php\/2022\/01\/24\/salt-sddc-modules-state-files\/","title":{"rendered":"Salt SDDC Modules &#8211; State Files"},"content":{"rendered":"\n<p>My previous <a href=\"https:\/\/nine30.info\/wp-admin\/post-new.php?post_type=post&amp;jetpack-copy=1545\" target=\"_blank\" rel=\"noreferrer noopener\">post<\/a> 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.<\/p>\n\n\n\n<p>At the time I am writing this post there aren&#8217;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!<\/p>\n\n\n\n<p>This post is a follow up on my <a rel=\"noreferrer noopener\" href=\"https:\/\/nine30.info\/wp-admin\/post-new.php?post_type=post&amp;jetpack-copy=1545\" target=\"_blank\">introductory post<\/a> 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&#8217;t harmful: vCenter VM Folder management. Next post will be more interesting as I&#8217;ll cover VMware Cloud on AWS (VMC) security configurations. <\/p>\n\n\n\n<p>Add <code>~\/salt\/srv\/salt\/folder_manage.sls<\/code> State file with the following content:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>create_folder:\n  vmware_folder.manage:\n    - name: sddc_extensions\n    - task: create\n    - dc_name: 'Region A'\n    - type: vm<\/code><\/pre>\n\n\n\n<p>Here we are using State Module <code>vmware_folder<\/code> which come with <code>mange<\/code>, <code>rename<\/code> and <code>move<\/code> functions. In this case we are using <code>manage<\/code> that creates or destroys a folder and requires the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>name<\/code>: the name of the folder<\/li><li><code>task<\/code>: <code>create<\/code> or <code>destroy<\/code><\/li><li><code>dc_name<\/code>: the name of the datacenter where the folder will be created (or deleted)<\/li><li><code>type<\/code>: the type of the folder to be created, possible options are: <code>vm, host, datastore<\/code> and <code>network<\/code><\/li><\/ul>\n\n\n\n<p>So, with the State file above we can create a new Virtual Machine folder named &#8220;sddc_extensions&#8221; in the Datacenter named &#8220;Region A&#8221;. Let&#8217;s do it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>salt-call state.apply folder_manage<\/code><\/pre>\n\n\n\n<p>In order to remove the newly created folder we could reuse the same state file only changing <code>task<\/code> from <code>create<\/code> to <code>destroy<\/code>. But let&#8217;s try something different. I stated before that currently there aren&#8217;t many State Modules, however we have a good number of Execution Modules functionalities. Thus, we can use the <code>module.run<\/code> capability  that allows individual Execution Module call from State files, you can get deeper on this approach <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.saltproject.io\/en\/latest\/ref\/states\/all\/salt.states.module.html\" target=\"_blank\">here<\/a>. <\/p>\n\n\n\n<p>Add file <code>~\/salt\/srv\/salt\/folder_destroy.sls<\/code> with the following content:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>destroy_folder:\n  module.run:\n    - name: vmware_folder.destroy\n    - folder_name: sddc_extensions\n    - dc_name: 'Region A'\n    - type: vm<\/code><\/pre>\n\n\n\n<p>In this State file we are calling the <code>destroy<\/code> function from the <code>vmware_folder<\/code> Execution Module passing the required parameters (<code>folder_name<\/code>, <code>dc_name<\/code> and <code>type<\/code>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta charset=\"utf-8\">salt-call state.apply folder_destroy<\/code><\/pre>\n\n\n\n<p>That&#8217;s it for today. Next post will cover some more compelling security for VMC use case.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t&hellip; <a class=\"more-link\" href=\"https:\/\/nine30.nxt70.com\/index.php\/2022\/01\/24\/salt-sddc-modules-state-files\/\">Continue reading <span class=\"screen-reader-text\">Salt SDDC Modules &#8211; State Files<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":580,"comment_status":"open","ping_status":"open","sticky":false,"template":"templates\/template-cover.php","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[5,23,65,88,122,126,143,159,178,191],"class_list":["post-1632","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech","tag-sddc","tag-automation","tag-folder","tag-iac","tag-opensource","tag-oss","tag-salt","tag-statefile","tag-vmware","tag-vsphere","entry"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/nine30.nxt70.com\/index.php\/wp-json\/wp\/v2\/posts\/1632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nine30.nxt70.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nine30.nxt70.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nine30.nxt70.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nine30.nxt70.com\/index.php\/wp-json\/wp\/v2\/comments?post=1632"}],"version-history":[{"count":0,"href":"https:\/\/nine30.nxt70.com\/index.php\/wp-json\/wp\/v2\/posts\/1632\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nine30.nxt70.com\/index.php\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/nine30.nxt70.com\/index.php\/wp-json\/wp\/v2\/media?parent=1632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nine30.nxt70.com\/index.php\/wp-json\/wp\/v2\/categories?post=1632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nine30.nxt70.com\/index.php\/wp-json\/wp\/v2\/tags?post=1632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}