<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python Archives - VirtJunkie</title>
	<atom:link href="/category/automation/scripting/python/feed/" rel="self" type="application/rss+xml" />
	<link>/category/automation/scripting/python/</link>
	<description>Virtualization, Automation, and anything else that might be on my mind</description>
	<lastBuildDate>Tue, 27 Jul 2021 12:53:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.5</generator>

<image>
	<url>/wp-content/uploads/2020/04/cropped-vj4-150x150.png</url>
	<title>Python Archives - VirtJunkie</title>
	<link>/category/automation/scripting/python/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Configure vROps To Send Alerts to OpsGenie and Microsoft Teams</title>
		<link>/2021/07/23/vrops-opsgenie-production-setup/</link>
					<comments>/2021/07/23/vrops-opsgenie-production-setup/#comments</comments>
		
		<dc:creator><![CDATA[Jon]]></dc:creator>
		<pubDate>Fri, 23 Jul 2021 18:35:59 +0000</pubDate>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Hashicorp]]></category>
		<category><![CDATA[InfrastructureAsCode]]></category>
		<category><![CDATA[Packer]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[vExpert]]></category>
		<category><![CDATA[VMware]]></category>
		<guid isPermaLink="false">https://www.virtjunkie.com/?p=1431</guid>

					<description><![CDATA[<p>Packer, Photon, Python, Flask, WSGI, vROps. Holy smokes folks.. I&#8217;m not sure I could make a more click-bait-y post if I tried! I recently took a position at a new company and had the opportunity to stand up a greenfield environment. Part of this environment was obviously configuring monitoring. Since we&#8217;re pretty heavily tied to [&#8230;]</p>
<p>The post <a href="/2021/07/23/vrops-opsgenie-production-setup/">Configure vROps To Send Alerts to OpsGenie and Microsoft Teams</a> appeared first on <a href="/">VirtJunkie</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Packer, Photon, Python, Flask, WSGI, vROps. Holy smokes folks.. I&#8217;m not sure I could make a more click-bait-y post if I tried!</p>



<p>I recently took a position at a new company and had the opportunity to stand up a greenfield environment. Part of this environment was obviously configuring monitoring. Since we&#8217;re pretty heavily tied to VMware here, we&#8217;re using vROps for our monitoring. For escalation of alerts, we&#8217;re using OpsGenie, and for normal collaboration we&#8217;re using Teams. Unfortunately, vROps versions older than 8.4 do not support sending alerts to OpsGenie or Teams out of the box. Fortunately, we can still get this working with a bit of work.</p>



<span id="more-1431"></span>



<h2 class="wp-block-heading">Overview</h2>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-1 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:66.66%">
<p class="has-black-color has-pale-cyan-blue-background-color has-text-color has-background">Update &#8211; Starting in vROps 8.4 you can use the webhook plugin that is delivered with vROps to accomplish this. <a href="https://docs.vmware.com/en/vRealize-Operations-Manager/8.4/com.vmware.vcom.core.doc/GUID-9314313D-1DE6-4160-AEFD-76B23AB5DAD9.html" target="_blank" rel="noreferrer noopener"><strong>LINK</strong></a></p>



<p>While vROps does have the ability to send outgoing notifications via REST API, it doesn&#8217;t have the ability to let you customize what fields are sent, or how they are formatted. Because of this limitation, <a rel="noreferrer noopener" href="https://github.com/vmw-loginsight/webhook-shims/graphs/contributors" target="_blank">some very thoughtful folks</a> created <a rel="noreferrer noopener" href="https://github.com/vmw-loginsight/webhook-shims" target="_blank">a project called webhook-shims</a>. This is essentially a Python Flask project that accepts web requests, translates them, then forwards the correctly formatted request off to whatever system you want notifications sent to.</p>



<p>This project hasn&#8217;t been updated in over 3 years, has a number of pending PR&#8217;s and Issues, so my spidey sense says it&#8217;s likely dead. So please be smart about how and where you use this, and consider the implications of running this in production. That said, from a functional standpoint, it seems to work well, and in the rest of this post I&#8217;ll go over how to set this up to run in a production fashion.</p>



<p>The list to the right are the applications that the project supports, and the bold items are what I&#8217;ll show example configuration for.</p>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow" style="flex-basis:33.33%">
<ul><li>bigpanda</li><li>bugzilla</li><li>groove</li><li>hipchat</li><li>jenkins</li><li>jira</li><li>kafkatopic</li><li><strong>opsgenie</strong></li><li>pagerduty</li><li>pivotaltracker</li><li>pushbullet</li><li>servicenow</li><li>slack</li><li>socialcast</li><li>travisci</li><li>vrealizeorchestrator</li><li>zendesk</li><li>moogsoft</li><li><strong>msteams</strong></li></ul>
</div>
</div>



<h2 class="wp-block-heading">Approach</h2>



<p>We&#8217;ll be running this whole project using Photon OS 4.</p>



<p>While we could simply run the python script in a <a rel="noreferrer noopener" href="https://www.gnu.org/software/screen/" target="_blank">screen</a>, <a rel="noreferrer noopener" href="https://github.com/tmux/tmux/wiki" target="_blank">tmux</a>, or similar session, but there are serious limitations in doing that. Admittedly, my python isn&#8217;t as strong as some of my other scripting languages, but after a bit of digging, it became clear that things like security, performance, and monitoring are either limited or unavailable if we do this. We&#8217;ll use a WSGI server called <a rel="noreferrer noopener" href="https://gunicorn.org/" target="_blank">Gunicorn</a> to run the python script, and use systemd to create a socket and service, and finally, use Nginx to connect directly to the socket. Whew! Even just reading that after completing this entire project feels like a lot, but don&#8217;t worry. As always, I&#8217;ll explain each step in detail and give you code to create this project.</p>



<h2 class="wp-block-heading">Create Photon Packer Template</h2>



<p>If you don&#8217;t know this about me by now, I&#8217;m a huge fan of packer. As such, we&#8217;ll be using it to create a template. You can find the source code for this packer template on <a href="https://github.com/jonhowe/Virtjunkie.com/tree/master/Packer/PhotonOS4" data-type="URL" data-id="https://github.com/jonhowe/Virtjunkie.com/tree/master/Packer/PhotonOS4">my website&#8217;s github repository</a></p>



<p>To get a local copy, run the following command:</p>



<p>
			<span id="urvanov-syntax-highlighter-667f6dd678f30132787977" class="urvanov-syntax-highlighter-syntax urvanov-syntax-highlighter-syntax-inline  crayon-theme-classic crayon-theme-classic-inline urvanov-syntax-highlighter-font-monaco" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important;"><span class="crayon-pre urvanov-syntax-highlighter-code" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-e">git </span><span class="crayon-r">clone</span><span class="crayon-h"> </span><span class="crayon-v">https</span><span class="crayon-o">:</span><span class="crayon-o">/</span><span class="crayon-o">/</span><span class="crayon-v">github</span><span class="crayon-e">.com</span><span class="crayon-o">/</span><span class="crayon-v">jonhowe</span><span class="crayon-o">/</span><span class="crayon-v">Virtjunkie</span><span class="crayon-e">.com</span><span class="crayon-e">.git</span></span></span></p>



<p>You can find all source code in the directory Virtjunkie.com/Packer/PhotonOS4.</p>



<h3 class="wp-block-heading">Create Custom ISO</h3>



<p>Unfortunately, Photon OS, even in v4, doesn&#8217;t support providing the kickstart file via CD-ROM or floppy (see <a rel="noreferrer noopener" href="https://github.com/vmware/photon/issues/1113" target="_blank">Issue#1113</a>, <a rel="noreferrer noopener" href="https://github.com/vmware/photon/issues/798" data-type="URL" data-id="https://github.com/vmware/photon/issues/798" target="_blank">Issue#798)</a>.  Unfortunately, this means that if we want (or need) to use the vsphere-iso builder, we&#8217;ll need to create an ISO with the kickstart file embedded. <a rel="noreferrer noopener" href="https://vmware.github.io/photon/docs/user-guide/working-with-kickstart/#building-an-iso-with-a-kickstart-config-file" target="_blank">I&#8217;m not going to duplicate documentation, so here&#8217;s the official documentation from VMware on how to add a kickstart file.</a></p>



<p>Instead of using the sample my_ks.cfg file provided in the ISO, use the version below.</p>



<p class="has-black-color has-luminous-vivid-amber-background-color has-text-color has-background">IMPORTANT: Ensure that you replace [yourpassword] with your actual password</p>



<script src="https://gist.github.com/jonhowe/7da290c7cfd660ddb220c96349d0f024.js"></script>



<h3 class="wp-block-heading">Use Packer To Create vSphere Template</h3>



<p class="has-luminous-vivid-amber-background-color has-background">IMPORTANT: Ensure that the password assigned to &#8220;root_password&#8221; in Virtjunkie.com/Packer/PhotonOS4/packer-photon.json.pkr.hcl matches what is set in the kickstart file above</p>



<pre class="urvanov-syntax-highlighter-plain-tag">packer build -var-file=nable.auto.pkrvars.hcl -var-file=vars iso-local-4.0GA.json -only=vsphere-iso.vmware-template packer-photon.json.pkr.hcl</pre>



<h2 class="wp-block-heading">Deploy Photon 4 VM</h2>



<p>For production systems, I typically use Terraform to deploy my VMs, and that&#8217;s what I did. I&#8217;m not going to go over that, as I&#8217;ve done it before. If nothing else, just deploy the VM from a template, assign it a static IP in the guest customization specification, and then log in using credentials set in the kickstart file.</p>



<h2 class="wp-block-heading">Configure Server</h2>



<h3 class="wp-block-heading">Install Packages</h3>



<p>Execute the commands below to install required packages, and to clone the repository</p>



<script src="https://gist.github.com/jonhowe/b66c9d6881db4ec00c30852d292f6102.js"></script>



<h3 class="wp-block-heading">Configure Shims</h3>



<p>There&#8217;s a bit of config we&#8217;ll need to do in order to make this production ready.</p>



<h4 class="wp-block-heading">Configure Teams</h4>



<p>A fellow VMware vExpert, Shane Moore has an excellent article. So that I don&#8217;t recreate the wheel, please <a rel="noreferrer noopener" href="https://www.virtuallyshane.com/posts/how-to-send-vrealize-operations-alerts-into-microsoft-teams" target="_blank">see his instructions</a> for how to prep your environment to use Microsoft Teams.</p>



<p>In short, you&#8217;ll create a webhook connector in the Microsoft Teams channel, and plug the URL that you get from Teams into the teams shim file.</p>



<h4 class="wp-block-heading">Configure OpsGenie</h4>



<p>OpsGenie is pretty simple. All we&#8217;ll need to do is create an integration by selecting your team in Opsgenie, navigating to Integrations, then selecting Add Integration.</p>



<figure class="wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><a href="https://www.virtjunkie.com/wp-content/uploads/2021/07/image-1024x138.png"><img fetchpriority="high" decoding="async" width="1024" height="138" src="https://www.virtjunkie.com/wp-content/uploads/2021/07/image-1024x138.png" alt="" data-id="1447" class="wp-image-1447" srcset="/wp-content/uploads/2021/07/image-1024x138.png 1024w, /wp-content/uploads/2021/07/image-300x40.png 300w, /wp-content/uploads/2021/07/image-768x104.png 768w, /wp-content/uploads/2021/07/image-1536x207.png 1536w, /wp-content/uploads/2021/07/image.png 1660w" sizes="(max-width: 1024px) 100vw, 1024px" /></a></figure></li></ul></figure>



<p>In the resulting list of available integrations, select API.</p>



<figure class="wp-block-gallery columns-1 is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><a href="https://www.virtjunkie.com/wp-content/uploads/2021/07/image-1.png"><img decoding="async" width="229" height="189" src="https://www.virtjunkie.com/wp-content/uploads/2021/07/image-1.png" alt="" data-id="1448" class="wp-image-1448"/></a></figure></li></ul></figure>



<p>Then note the API key (you can grab it later, it doesn&#8217;t disappear when you navigate away). We&#8217;ll use that when we configure outbound settings in vROps to use OpsGenie.</p>



<h4 class="wp-block-heading">Disable Unused Shims</h4>



<p>In my environment, I&#8217;m only going to be using Teams and OpsGenie alerts. To reduce bloat and access points that could cause me security issues, I&#8217;m disabling all shims not in use.</p>



<p>Edit the file 
			<span id="urvanov-syntax-highlighter-667f6dd678f3c372413635" class="urvanov-syntax-highlighter-syntax urvanov-syntax-highlighter-syntax-inline  crayon-theme-classic crayon-theme-classic-inline urvanov-syntax-highlighter-font-monaco" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important;"><span class="crayon-pre urvanov-syntax-highlighter-code" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">loginsightwebhookdemo</span><span class="crayon-o">/</span><span class="crayon-v">webhook</span><span class="crayon-o">-</span><span class="crayon-v">shims</span><span class="crayon-o">/</span><span class="crayon-v">loginsightwebhookdemo</span><span class="crayon-o">/</span><span class="crayon-v">__init__</span><span class="crayon-sy">.</span><span class="crayon-v">py</span></span></span></p>



<script src="https://gist.github.com/jonhowe/1d6fa1a003732c7200ec1ca28e509751.js"></script>



<h4 class="wp-block-heading">Disable Welcome Page</h4>



<p>This could probably be optional, but I appreciate not having a welcome/hello world webpage open for a production service. We&#8217;ll disable it.</p>



<p><meta http-equiv="content-type" content="text/html; charset=utf-8">Edit the file 
			<span id="urvanov-syntax-highlighter-667f6dd678f40596796082" class="urvanov-syntax-highlighter-syntax urvanov-syntax-highlighter-syntax-inline  crayon-theme-classic crayon-theme-classic-inline urvanov-syntax-highlighter-font-monaco" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important;"><span class="crayon-pre urvanov-syntax-highlighter-code" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">loginsightwebhookdemo</span><span class="crayon-o">/</span><span class="crayon-v">webhook</span><span class="crayon-o">-</span><span class="crayon-v">shims</span><span class="crayon-o">/</span><span class="crayon-v">loginsightwebhookdemo</span><span class="crayon-o">/</span><span class="crayon-v">__init__</span><span class="crayon-sy">.</span><span class="crayon-v">py</span></span></span></p>



<script src="https://gist.github.com/jonhowe/872a49c369ee36ff9bee6be431572a49.js"></script>



<h2 class="wp-block-heading">Configure Systemd</h2>



<p>Create two files: 
			<span id="urvanov-syntax-highlighter-667f6dd678f41189097526" class="urvanov-syntax-highlighter-syntax urvanov-syntax-highlighter-syntax-inline  crayon-theme-classic crayon-theme-classic-inline urvanov-syntax-highlighter-font-monaco" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important;"><span class="crayon-pre urvanov-syntax-highlighter-code" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-o">/</span><span class="crayon-v">etc</span><span class="crayon-o">/</span><span class="crayon-v">systemd</span><span class="crayon-o">/</span><span class="crayon-v">system</span><span class="crayon-o">/</span><span class="crayon-v">gunicorn</span><span class="crayon-sy">.</span><span class="crayon-v">service</span></span></span> and 
			<span id="urvanov-syntax-highlighter-667f6dd678f43826686282" class="urvanov-syntax-highlighter-syntax urvanov-syntax-highlighter-syntax-inline  crayon-theme-classic crayon-theme-classic-inline urvanov-syntax-highlighter-font-monaco" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important;"><span class="crayon-pre urvanov-syntax-highlighter-code" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-o">/</span><span class="crayon-v">etc</span><span class="crayon-o">/</span><span class="crayon-v">systemd</span><span class="crayon-o">/</span><span class="crayon-v">system</span><span class="crayon-o">/</span><span class="crayon-v">gunicorn</span><span class="crayon-sy">.</span><span class="crayon-v">socket</span></span></span> and populate with the text below. </p>



<p>
			<span id="urvanov-syntax-highlighter-667f6dd678f44774188370" class="urvanov-syntax-highlighter-syntax urvanov-syntax-highlighter-syntax-inline  crayon-theme-classic crayon-theme-classic-inline urvanov-syntax-highlighter-font-monaco" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important;"><span class="crayon-pre urvanov-syntax-highlighter-code" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-o">/</span><span class="crayon-v">etc</span><span class="crayon-o">/</span><span class="crayon-v">systemd</span><span class="crayon-o">/</span><span class="crayon-v">system</span><span class="crayon-o">/</span><span class="crayon-v">gunicorn</span><span class="crayon-sy">.</span><span class="crayon-v">service</span></span></span></p>



<p>This service file ensures that Gunicorn is started the same way, and is managed by systemd. You&#8217;ll note that it <em>requires</em> gunicorn.socket, which we will create later.</p>



<script src="https://gist.github.com/jonhowe/e6b1d294dca6235f00b80c58a6f31af6.js"></script>



<p>
			<span id="urvanov-syntax-highlighter-667f6dd678f45695430813" class="urvanov-syntax-highlighter-syntax urvanov-syntax-highlighter-syntax-inline  crayon-theme-classic crayon-theme-classic-inline urvanov-syntax-highlighter-font-monaco" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important;"><span class="crayon-pre urvanov-syntax-highlighter-code" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-o">/</span><span class="crayon-v">etc</span><span class="crayon-o">/</span><span class="crayon-v">systemd</span><span class="crayon-o">/</span><span class="crayon-v">system</span><span class="crayon-o">/</span><span class="crayon-v">gunicorn</span><span class="crayon-sy">.</span><span class="crayon-v">socket</span></span></span></p>



<p>This socket file sets permissions for the socket assigned to gunicorn</p>



<script src="https://gist.github.com/jonhowe/8398a06c4395763a82faa480de19206e.js"></script>



<h2 class="wp-block-heading">Configure Nginx</h2>



<p>Replace the file 
			<span id="urvanov-syntax-highlighter-667f6dd678f46696413254" class="urvanov-syntax-highlighter-syntax urvanov-syntax-highlighter-syntax-inline  crayon-theme-classic crayon-theme-classic-inline urvanov-syntax-highlighter-font-monaco" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important;"><span class="crayon-pre urvanov-syntax-highlighter-code" style="font-size: 12px !important; line-height: 15px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-o">/</span><span class="crayon-v">etc</span><span class="crayon-o">/</span><span class="crayon-v">nginx</span><span class="crayon-o">/</span><span class="crayon-v">nginx</span><span class="crayon-sy">.</span><span class="crayon-v">conf</span></span></span> with the contents below</p>



<p>This is telling Nginx to connect directly to the socket we&#8217;re creating with the systemd socket gunicorn.socket we created earlier.</p>



<script src="https://gist.github.com/jonhowe/78964d1cc4a32bf5e13a7369a36eaa13.js"></script>



<h2 class="wp-block-heading">Enable and Start All Services</h2>



<p>Finally, enable, and start both services, and restart Nginx</p>



<div class="wp-block-urvanov-syntax-highlighter-code-block"><pre class="urvanov-syntax-highlighter-plain-tag">systemctl enable gunicorn.socket
systemctl enable gunicorn.service
systemctl restart gunicorn.socket 
systemctl restart gunicorn.service
systemctl restart nginx.service</pre></div>



<h2 class="wp-block-heading">Configure vRealize Operations Manager</h2>



<p>At this point, all we need to do is configure an outbound instance for Microsoft Teams and OpsGenie. </p>



<h3 class="wp-block-heading">Add a New Rest Notification Plugin</h3>



<h4 class="wp-block-heading">OpsGenie</h4>



<p>To do this, sign into vROps, and navigate to Administration -&gt;Management-&gt;Outbound Settings, or https://[Your_vROps_URL]/ui/index.action#/administration/outbound-alert-settings</p>



<figure class="wp-block-gallery columns-1 is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><a href="https://www.virtjunkie.com/wp-content/uploads/2021/07/image-2.png"><img decoding="async" width="636" height="351" src="https://www.virtjunkie.com/wp-content/uploads/2021/07/image-2.png" alt="" data-id="1452" class="wp-image-1452" srcset="/wp-content/uploads/2021/07/image-2.png 636w, /wp-content/uploads/2021/07/image-2-300x166.png 300w" sizes="(max-width: 636px) 100vw, 636px" /></a></figure></li></ul></figure>



<p>After you select the Rest Notification Plugin, there are 3 fields required in the Add/Edit Outbound Instance box</p>



<figure class="wp-block-table"><table><tbody><tr><td>Item</td><td>Description</td><td>Example</td></tr><tr><td>Instance Name</td><td>Name of the rest notification plugin created</td><td>Opsgenie</td></tr><tr><td>URL</td><td>URL to OpsGenie shim endpoint</td><td>http://&lt;IP/ or Hostname of Photon VM&gt;/endpoint/opsgenie/&lt;api key&gt;</td></tr><tr><td>Content Type</td><td>Content Type &#8211; Unless you&#8217;re working with a SOAP API (which we aren&#8217;t), this will always be application/json</td><td></td></tr></tbody></table></figure>



<figure class="wp-block-gallery columns-1 is-cropped wp-block-gallery-4 is-layout-flex wp-block-gallery-is-layout-flex"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><a href="https://www.virtjunkie.com/wp-content/uploads/2021/07/image-3.png"><img loading="lazy" decoding="async" width="580" height="479" src="https://www.virtjunkie.com/wp-content/uploads/2021/07/image-3.png" alt="" data-id="1453" class="wp-image-1453" srcset="/wp-content/uploads/2021/07/image-3.png 580w, /wp-content/uploads/2021/07/image-3-300x248.png 300w" sizes="(max-width: 580px) 100vw, 580px" /></a></figure></li></ul></figure>



<p>Finally, navigate to Alerts -&gt; Configuration -&gt; Notification (https://<meta http-equiv="content-type" content="text/html; charset=utf-8">[Your_vROps_URL]/ui/index.action#/alerts/notifications) and add a new rule that targets the adapter you just created.</p>



<figure class="wp-block-gallery columns-1 is-cropped wp-block-gallery-5 is-layout-flex wp-block-gallery-is-layout-flex"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><a href="https://www.virtjunkie.com/wp-content/uploads/2021/07/image-4.png"><img loading="lazy" decoding="async" width="883" height="486" src="https://www.virtjunkie.com/wp-content/uploads/2021/07/image-4.png" alt="" data-id="1454" class="wp-image-1454" srcset="/wp-content/uploads/2021/07/image-4.png 883w, /wp-content/uploads/2021/07/image-4-300x165.png 300w, /wp-content/uploads/2021/07/image-4-768x423.png 768w" sizes="(max-width: 883px) 100vw, 883px" /></a></figure></li></ul></figure>



<h4 class="wp-block-heading">Teams</h4>



<p>Again, I&#8217;m not in the business of recreating the wheel, <a href="https://www.virtuallyshane.com/posts/how-to-send-vrealize-operations-alerts-into-microsoft-teams" target="_blank" rel="noreferrer noopener">so check out Shane&#8217;s blog for info on how to do this</a>.</p>



<h2 class="wp-block-heading">References</h2>



<figure class="wp-block-table"><table><tbody><tr><td><a href="https://www.virtuallyshane.com/posts/how-to-send-vrealize-operations-alerts-into-microsoft-teams" target="_blank" rel="noreferrer noopener">https://www.virtuallyshane.com/posts/how-to-send-vrealize-operations-alerts-into-microsoft-teams</a></td><td>Fellow vExpert Shane Moore&#8217;s article for setting MS Teams forwarding</td></tr><tr><td><a href="https://github.com/vmw-loginsight/webhook-shims" target="_blank" rel="noreferrer noopener">https://github.com/vmw-loginsight/webhook-shims</a></td><td>Official Github site for the webhook-shims project</td></tr><tr><td><a href="https://blogs.vmware.com/management/2017/01/vrealize-webhooks-infinite-integrations.html" target="_blank" rel="noreferrer noopener">https://blogs.vmware.com/management/2017/01/vrealize-webhooks-infinite-integrations.html</a></td><td>VMware Blog article that got me started on this journey</td></tr><tr><td><a href="https://vmware.github.io/photon/docs/user-guide/working-with-kickstart/" target="_blank" rel="noreferrer noopener">https://vmware.github.io/photon/docs/user-guide/working-with-kickstart/</a></td><td>VMware Photon documentation</td></tr><tr><td><a href="https://github.com/vmware/photon/issues/1113" target="_blank" rel="noreferrer noopener">https://github.com/vmware/photon/issues/1113</a></td><td>Github Issue for presenting Kickstart file to Photon over cdrom/floppy</td></tr><tr><td><a href="https://github.com/vmware/photon/issues/798" target="_blank" rel="noreferrer noopener">https://github.com/vmware/photon/issues/798</a></td><td><meta http-equiv="content-type" content="text/html; charset=utf-8">Another Github Issue for presenting Kickstart file to Photon over cdrom/floppy</td></tr></tbody></table></figure>
<p>The post <a href="/2021/07/23/vrops-opsgenie-production-setup/">Configure vROps To Send Alerts to OpsGenie and Microsoft Teams</a> appeared first on <a href="/">VirtJunkie</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>/2021/07/23/vrops-opsgenie-production-setup/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Poor Man&#8217;s AutoDeploy Using Custom Kickstart, and Python</title>
		<link>/2020/04/09/poor-mans-autodeploy/</link>
					<comments>/2020/04/09/poor-mans-autodeploy/#comments</comments>
		
		<dc:creator><![CDATA[Jon]]></dc:creator>
		<pubDate>Thu, 09 Apr 2020 13:00:00 +0000</pubDate>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[VMware]]></category>
		<guid isPermaLink="false">http://www.virtjunkie.com/?p=1107</guid>

					<description><![CDATA[<p>I recently encountered a situation where I needed to provision hundreds of ESXi hosts. The thing is, there was no vSphere Autodeploy, or HPE Synergy Image Streamer, and no ability to (long story, trust me here). No way I'm going to manually provision all of those hosts by hand, so what's a guy to do?!</p>
<p>While I designed this solution to work with hundreds of production ESXi hosts, there's nothing from preventing you from using this method in smaller production environments, or even your own home lab.</p>
<p>The post <a href="/2020/04/09/poor-mans-autodeploy/">Poor Man&#8217;s AutoDeploy Using Custom Kickstart, and Python</a> appeared first on <a href="/">VirtJunkie</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I recently encountered a situation where I needed to provision hundreds of ESXi hosts. The thing is, there was no vSphere Autodeploy, or HPE Synergy Image Streamer, and no ability to (long story, trust me here) spin them up. No way I&#8217;m going to manually provision all of those hosts by hand, so what&#8217;s a guy to do?!</p>



<p>This solution will automatically provision ESXi hosts and &#8220;get them on the network&#8221; so you can add them to vCenter just by using tools that VMware gives us, and a little bit of creativity.</p>



<p>While I designed this solution to work with hundreds of production ESXi hosts, there&#8217;s nothing from preventing you from using this method in smaller production environments, or even your own home lab.</p>



<span id="more-1107"></span>



<h2 class="wp-block-heading">Overview</h2>



<p>At a very high level, the process works as follows.. The physical server boots from an ISO, USB Image, or even CD/DVD, if you&#8217;re into that sort of thing. The ESXi image on this media will contain a slightly customized ESXi image that looks for a kickstart file pulls the rest of the install instructions from a kickstart file on a web server. This kickstart fill will handle the silent install of ESXi, reboot into the newly installed OS, set a few settings, then download a CSV that contains ESXi host configuration info (such as host name, IP, and Default Gateway), and a python script that will send esxcli commands to the host in order to configure networking.</p>



<h3 class="wp-block-heading">Diagram</h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="412" src="https://new.virtjunkie.com/wp-content/uploads/2020/04/Poor-Mans-AutoDeploy-1024x412.jpeg" alt="" class="wp-image-1146" srcset="/wp-content/uploads/2020/04/Poor-Mans-AutoDeploy-1024x412.jpeg 1024w, /wp-content/uploads/2020/04/Poor-Mans-AutoDeploy-300x121.jpeg 300w, /wp-content/uploads/2020/04/Poor-Mans-AutoDeploy-768x309.jpeg 768w, /wp-content/uploads/2020/04/Poor-Mans-AutoDeploy-1536x617.jpeg 1536w, /wp-content/uploads/2020/04/Poor-Mans-AutoDeploy-2048x823.jpeg 2048w, /wp-content/uploads/2020/04/Poor-Mans-AutoDeploy-1568x630.jpeg 1568w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<h2 class="wp-block-heading">Modified Boot.cfg file</h2>



<p>First and foremost, I need to emphasize the fact that there are two places you need to put your boot.cfg file. One in the root of the filesystem you have on your media, and one in the efi folder. This file is read during the boot process and instructs ESXi on how to boot. We care about the line that begins with <strong>kernelopt=</strong>. By default, this line tells ESXi to start with the traditional GUI installer which we definitely don&#8217;t want. Instead, we&#8217;ll modify it to tell the installer to look for a kickstart file on a web server, and will set static networking for the host.</p>



<p>At a high level, the modifications here accomplish the following:</p>



<ol><li>Instruct the ESXi host to find a kickstart file on a web server</li><li>Set a static IP, netmask, default gateway, and nameserver to use prior to automatically configuring the host</li></ol>



<h3 class="wp-block-heading">boot.cfg code</h3>



<p><a href="https://github.com/jonhowe/Virtjunkie.com/tree/master/PoorMansAutoDeploy/esxi-iso" target="_blank" rel="noreferrer noopener">Here&#8217;s a link to the code</a></p>



<pre class="urvanov-syntax-highlighter-plain-tag">bootstate=0
title=Loading ESXi installer
timeout=5
prefix=
kernel=/b.b00
#kernelopt=cdromBoot runweasel
kernelopt=ks=http://vmware-ks.home.lab:8123/files/VMware/ks/ks.cfg nameserver=192.168.1.60 ip=192.168.1.5 netmask=255.255.255.0 gateway=192.168.1.1
modules=/jumpstrt.gz --- /useropts.gz --- /features.gz --- /k.b00 --- /chardevs.b00 --- /user.b00 --- /procfs.b00 --- /uc_intel.b00 --- /uc_amd.b00 --- /uc_hygon.b00 --- /vmx.v00 --- /vim.v00 --- /sb.v00 --- /s.v00 --- /ata_liba.v00 --- /ata_pata.v00 --- /ata_pata.v01 --- /ata_pata.v02 --- /ata_pata.v03 --- /ata_pata.v04 --- /ata_pata.v05 --- /ata_pata.v06 --- /ata_pata.v07 --- /block_cc.v00 --- /bnxtnet.v00 --- /bnxtroce.v00 --- /brcmfcoe.v00 --- /char_ran.v00 --- /ehci_ehc.v00 --- /elxiscsi.v00 --- /elxnet.v00 --- /hid_hid.v00 --- /i40en.v00 --- /iavmd.v00 --- /igbn.v00 --- /ima_qla4.v00 --- /ipmi_ipm.v00 --- /ipmi_ipm.v01 --- /ipmi_ipm.v02 --- /iser.v00 --- /ixgben.v00 --- /lpfc.v00 --- /lpnic.v00 --- /lsi_mr3.v00 --- /lsi_msgp.v00 --- /lsi_msgp.v01 --- /lsi_msgp.v02 --- /misc_cni.v00 --- /misc_dri.v00 --- /mtip32xx.v00 --- /ne1000.v00 --- /nenic.v00 --- /net_bnx2.v00 --- /net_bnx2.v01 --- /net_cdc_.v00 --- /net_cnic.v00 --- /net_e100.v00 --- /net_e100.v01 --- /net_enic.v00 --- /net_fcoe.v00 --- /net_forc.v00 --- /net_igb.v00 --- /net_ixgb.v00 --- /net_libf.v00 --- /net_mlx4.v00 --- /net_mlx4.v01 --- /net_nx_n.v00 --- /net_tg3.v00 --- /net_usbn.v00 --- /net_vmxn.v00 --- /nfnic.v00 --- /nhpsa.v00 --- /nmlx4_co.v00 --- /nmlx4_en.v00 --- /nmlx4_rd.v00 --- /nmlx5_co.v00 --- /nmlx5_rd.v00 --- /ntg3.v00 --- /nvme.v00 --- /nvmxnet3.v00 --- /nvmxnet3.v01 --- /ohci_usb.v00 --- /pvscsi.v00 --- /qcnic.v00 --- /qedentv.v00 --- /qfle3.v00 --- /qfle3f.v00 --- /qfle3i.v00 --- /qflge.v00 --- /sata_ahc.v00 --- /sata_ata.v00 --- /sata_sat.v00 --- /sata_sat.v01 --- /sata_sat.v02 --- /sata_sat.v03 --- /sata_sat.v04 --- /scsi_aac.v00 --- /scsi_adp.v00 --- /scsi_aic.v00 --- /scsi_bnx.v00 --- /scsi_bnx.v01 --- /scsi_fni.v00 --- /scsi_hps.v00 --- /scsi_ips.v00 --- /scsi_isc.v00 --- /scsi_lib.v00 --- /scsi_meg.v00 --- /scsi_meg.v01 --- /scsi_meg.v02 --- /scsi_mpt.v00 --- /scsi_mpt.v01 --- /scsi_mpt.v02 --- /scsi_qla.v00 --- /sfvmk.v00 --- /shim_isc.v00 --- /shim_isc.v01 --- /shim_lib.v00 --- /shim_lib.v01 --- /shim_lib.v02 --- /shim_lib.v03 --- /shim_lib.v04 --- /shim_lib.v05 --- /shim_vmk.v00 --- /shim_vmk.v01 --- /shim_vmk.v02 --- /smartpqi.v00 --- /uhci_usb.v00 --- /usb_stor.v00 --- /usbcore_.v00 --- /vmkata.v00 --- /vmkfcoe.v00 --- /vmkplexe.v00 --- /vmkusb.v00 --- /vmw_ahci.v00 --- /xhci_xhc.v00 --- /elx_esx_.v00 --- /btldr.t00 --- /esx_dvfi.v00 --- /esx_ui.v00 --- /esxupdt.v00 --- /weaselin.t00 --- /lsu_hp_h.v00 --- /lsu_inte.v00 --- /lsu_lsi_.v00 --- /lsu_lsi_.v01 --- /lsu_lsi_.v02 --- /lsu_lsi_.v03 --- /lsu_lsi_.v04 --- /lsu_smar.v00 --- /native_m.v00 --- /qlnative.v00 --- /rste.v00 --- /vmware_e.v00 --- /vsan.v00 --- /vsanheal.v00 --- /vsanmgmt.v00 --- /tools.t00 --- /xorg.v00 --- /imgdb.tgz --- /imgpayld.tgz
build=
updated=0</pre>
</div></div>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<h2 class="wp-block-heading">Kickstart file (ks.cfg)</h2>



<p>The kickstart file provides the ESXi installer with all the information it needs to perform the installation without manual intervention. We are handling this in two stages by using the firstboot parameter.</p>



<h3 class="wp-block-heading">Stage 1</h3>



<p>Handles the installation of ESXi to physical hardware. The following tasks are completed:</p>



<ol><li>Accept EULA</li><li>Select disk for ESXi to be installed to</li><li>Set root password</li><li>Set IP to be used on first boot (Default is DHCP, but the code to use static is included/commented in the code)</li></ol>



<h3 class="wp-block-heading">Stage 2</h3>



<p>All of stage two is executed in the newly installed ESXi OS using the firstboot parameter. The following tasks are completed:</p>



<ol><li>Enable SSH and ESXi Shell</li><li>Disable warnings for #1</li><li>Disable ESXi Firewall so we can use wget</li><li>Using wget, download the following files<ol><li>ListOfHosts.csv</li><li>configurehost.py</li></ol></li><li>Set the execution bit on the python script</li><li>Execute the python script</li></ol>



<h3 class="wp-block-heading">ks.cfg code</h3>



<p><a href="https://github.com/jonhowe/Virtjunkie.com/blob/master/PoorMansAutoDeploy/ks.cfg" target="_blank" rel="noreferrer noopener">Here&#8217;s a link to the code</a></p>



<pre class="urvanov-syntax-highlighter-plain-tag">#__      ___      _       _             _    _      
#\ \    / (_)    | |     | |           | |  (_)     
# \ \  / / _ _ __| |_    | |_   _ _ __ | | ___  ___ 
#  \ \/ / | | '__| __|   | | | | | '_ \| |/ / |/ _ \
#   \  /  | | |  | || |__| | |_| | | | |   &amp;lt;| |  __/
#    \/   |_|_|   \__\____/ \__,_|_| |_|_|\_\_|\___|

#Jon Howe
#https://www.virtjunkie.com/Poor-Mans-AutoDeploy
#https://github.com/jonhowe/Virtjunkie.com/tree/master/PoorMansAutoDeploy

#  _____ _                     __            _____           _        _ _       _   _             
# / ____| |                   /_ |          |_   _|         | |      | | |     | | (_)            
#| (___ | |_ __ _  __ _  ___   | |  ______    | |  _ __  ___| |_ __ _| | | __ _| |_ _  ___  _ __  
# \___ \| __/ _` |/ _` |/ _ \  | | |______|   | | | '_ \/ __| __/ _` | | |/ _` | __| |/ _ \| '_ \ 
# ____) | || (_| | (_| |  __/  | |           _| |_| | | \__ \ || (_| | | | (_| | |_| | (_) | | | |
#|_____/ \__\__,_|\__, |\___|  |_|          |_____|_| |_|___/\__\__,_|_|_|\__,_|\__|_|\___/|_| |_|
#                  __/ |                                                                          
#                 |___/                                                                           

# Accept the VMware End User License Agreement
vmaccepteula

# The install media is in the CD-ROM drive
#   This was the hardest part for some reason. I was installing from a USB drive TO a separate USB drive.
#   https://docs.vmware.com/en/VMware-vSphere/6.7/com.vmware.esxi.upgrade.doc/GUID-61A14EBB-5CF3-43EE-87EF-DB8EC6D83698.html
#   https://docs.vmware.com/en/VMware-vSphere/6.7/com.vmware.esxi.upgrade.doc/GUID-E7274FBA-CABC-43E8-BF74-2924FD3EFE1E.html
#   If you find the wrong device is being selected, you can hit CTRL+F1 during the install, log in (root/&amp;#91;no password]) and enter
#   the following command to get a list of the available devices:
#   localcli storage core device list
install --disk=/vmfs/devices/disks/mpx.vmhba33:C0:T0:L0 --overwritevmfs --novmfsondisk

# Set the root password for the DCUI and Tech Support Mode
rootpw VMware1!

### Temporary Network Configuration
#   Keep in mind, this is temporary. The actual IP address will be set in Stage 2
#   We don't even technically need this, but I wanted to include it in case we need network connectivity in Stage 1

# Set the network to DHCP on the first network adapter
network --bootproto=dhcp --device=vmnic0
# ... or if you want, you can set this to static
# network --bootproto=static --ip=192.168.30.13 --netmask=255.255.255.0 --gateway=192.168.30.1 --hostname=esxi1-mgmt.home.lab --nameserver=192.168.0.1 --addvmportgroup=1

reboot

#  _____ _                     ___              _____ _                 _         _____             __ _       
# / ____| |                   |__ \            / ____(_)               | |       / ____|           / _(_)      
#| (___ | |_ __ _  __ _  ___     ) |  ______  | (___  _ _ __ ___  _ __ | | ___  | |     ___  _ __ | |_ _  __ _ 
# \___ \| __/ _` |/ _` |/ _ \   / /  |______|  \___ \| | '_ ` _ \| '_ \| |/ _ \ | |    / _ \| '_ \|  _| |/ _` |
# ____) | || (_| | (_| |  __/  / /_            ____) | | | | | | | |_) | |  __/ | |___| (_) | | | | | | | (_| |
#|_____/ \__\__,_|\__, |\___| |____|          |_____/|_|_| |_| |_| .__/|_|\___|  \_____\___/|_| |_|_| |_|\__, |
#                  __/ |                                         | |                                      __/ |
#                 |___/                                          |_|                                     |___/ 

%firstboot --interpreter=busybox

# enable &amp;amp; start SSH
vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh

# enable &amp;amp; start ESXi Shell
vim-cmd hostsvc/enable_esx_shell
vim-cmd hostsvc/start_esx_shell

# Suppress ESXi Shell warning
esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1

#Temporarily disable the firewall so we can grab a couple files using wget
esxcli network firewall set --enabled false

# Download Host Config CSV, host configuration script, and execute the host configuration script
wget -O ListOfHosts.csv http://jondesktop.home.lan:8123/files/VMware/ks/ListOfHosts.csv
wget -O configurehost.py http://jondesktop.home.lan:8123/files/VMware/ks/configurehost.py
chmod u+x configurehost.py
/bin/python configurehost.py

#Re-enable the firewall
esxcli network firewall set --enabled true</pre>
</div></div>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<h2 class="wp-block-heading">Host Detail Spreadsheet</h2>



<p>I like to have all, or as much configuration as possible defined in a document, and consume that as a part of the provisioning process. In this case, since I&#8217;m executing this on an ESXi host using the version of python that is available to the host, I&#8217;m simply using a CSV file. This strikes a healthy balance between usability and functionality.<br><br><a rel="noreferrer noopener" href="https://github.com/jonhowe/Virtjunkie.com/blob/master/PoorMansAutoDeploy/ListOfHosts.csv" target="_blank">Here&#8217;s a link to the CSV on my github account</a></p>



<p>The columns are as follows:</p>



<figure class="wp-block-table"><table><tbody><tr><td>Column A</td><td>ESXi Hostname</td></tr><tr><td>Column B</td><td>MAC Address of vmnic0</td></tr><tr><td>Column C</td><td>Desired Management IP Address (vmk0)</td></tr><tr><td>Column D</td><td>Subnet Mask for vmk0</td></tr><tr><td>Column E</td><td>Default Gateway for vmk0</td></tr><tr><td>Column F</td><td>VLAN Assigned to vmk0</td></tr></tbody></table><figcaption>Note: Columns have been converted to rows in this table. The actual representation is shown in the image below.</figcaption></figure>
</div></div>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="789" height="127" src="https://www.virtjunkie.com/wp-content/uploads/2020/04/image.png" alt="" class="wp-image-1137" srcset="/wp-content/uploads/2020/04/image.png 789w, /wp-content/uploads/2020/04/image-300x48.png 300w, /wp-content/uploads/2020/04/image-768x124.png 768w" sizes="(max-width: 789px) 100vw, 789px" /></figure>



<h2 class="wp-block-heading">configureHost.py</h2>



<p>Here&#8217;s where the magic comes in&#8230; Since ESXi is deployed with python, we can use it to parse a CSV file that has a list of all details for an ESXi host, and set the relevant details for the host.<br><a rel="noreferrer noopener" href="https://github.com/jonhowe/Virtjunkie.com/blob/master/PoorMansAutoDeploy/configurehost.py" target="_blank">Here&#8217;s a link to the code</a></p>



<p>In this very basic example, we are doing the following based on input in the CSV file:</p>



<ol><li>Set the hostname</li><li>Set the IP Address and Netmask of vmk0</li><li>Set the default gateway for the host</li><li>Set the VLAN for the management port group on vSwitch0</li></ol>
</div></div>



<h3 class="wp-block-heading">configureHost.py code</h3>



<pre class="urvanov-syntax-highlighter-plain-tag">#__      ___      _       _             _    _      
#\ \    / (_)    | |     | |           | |  (_)     
# \ \  / / _ _ __| |_    | |_   _ _ __ | | ___  ___ 
#  \ \/ / | | '__| __|   | | | | | '_ \| |/ / |/ _ \
#   \  /  | | |  | || |__| | |_| | | | |   &amp;lt;| |  __/
#    \/   |_|_|   \__\____/ \__,_|_| |_|_|\_\_|\___|
                                                  
#Jon Howe
#https://www.virtjunkie.com/Poor-Mans-AutoDeploy
#https://github.com/jonhowe/Virtjunkie.com/tree/master/PoorMansAutoDeploy

import os, csv, subprocess

CSVPATH = '/ListOfHosts.csv'

#Gets all mac addresses of interfaces
MAC=subprocess.check_output(&quot;esxcli network ip interface list |grep MAC | cut -d ' ' -f 6&quot;,shell=True)
                                                                                                                                                                                                                                                                                    
MACADDR = MAC.split()
print(&quot;MAC Addresses:&quot;)
print(MACADDR)

#Open the CSV file
with open(CSVPATH, 'rt') as csvFile:
        csvReader = csv.reader(csvFile)
        #Process the CSV file, row by row
        for csvRow in csvReader:
                #Check to see if the Mac Address of vmnic0 (IE: MACADDR&amp;#91;0]) matches the row in the CSV we are looking at
                if ((MACADDR&amp;#91;0]).decode('utf-8')) == csvRow&amp;#91;1]:
                        #print(&quot;esxcli system hostname set --fqdn=&quot; + csvRow&amp;#91;0])
                        #print(&quot;esxcli network ip interface ipv4 set --interface-name=vmk0 --ipv4=&quot; + csvRow&amp;#91;2] + &quot; --netmask=&quot; + csvRow&amp;#91;3] + &quot; --type=static&quot;)
                        
                        #Set the hostname to the value in the CSV
                        os.system(&quot;esxcli system hostname set --fqdn=&quot; + csvRow&amp;#91;0])
                        
                        #Set the IP Address and Netmask of vmk0
                        os.system(&quot;esxcli network ip interface ipv4 set --interface-name=vmk0 --ipv4=&quot; + csvRow&amp;#91;2] + &quot; --netmask=&quot; + csvRow&amp;#91;3] + &quot; --type=static&quot;)
                        
                        #Add the default gateway
                        os.system(&quot;esxcfg-route &quot; + csvRow&amp;#91;4])
                        
                        #Add the desired VLAN for the Management Network on the vSwitch that gets created by default (vSwitch0)
                        os.system(&quot;esxcfg-vswitch -p 'Management Network' -v &quot; + csvRow&amp;#91;5] + &quot; vSwitch0&quot;)</pre>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<h2 class="wp-block-heading">Web Server</h2>



<p>Since none of this works without a web server, we&#8217;ll need to make sure we have one available. My goal in creating this was to have the whole project be as portable as possible. To that effort, I use a small docker container I can start/stop on my laptop or workstation that hosts the required files, but there&#8217;s nothing preventing you from doing this on a production server as well. I&#8217;m using a container that has a nice graphical directory browser, but also allows for direct downloading of files. <a rel="noreferrer noopener" href="https://hub.docker.com/r/mohamnag/nginx-file-browser" target="_blank">Here&#8217;s a link to more information about this container</a></p>



<p>As a side note, in a <a rel="noreferrer noopener" href="https://www.virtjunkie.com/deploy-vcsa-via-powershell/" target="_blank">previous blog post, I spoke about deploying VCSA</a> based on properties in an Excel file. One of the prerequisites for this to work is to have a web server that hosts the ISO file. I use this same container to serve the files for that project.</p>



<h3 class="wp-block-heading">Docker Container</h3>



<p>The following snippet can be used to create a docker container to host the files required by this project.</p>



<pre class="urvanov-syntax-highlighter-plain-tag">docker run -p 8123:80 -v /storage/poormansautodeploy/ks/:/opt/www/files --name=filebrowser -d --restart unless-stopped --log-opt max-size=15m --log-opt max-file=2 mohamnag/nginx-file-browser</pre>



<h3 class="wp-block-heading">Directory structure</h3>



<pre class="urvanov-syntax-highlighter-plain-tag">ks
├── configurehost.py
├── ks.cfg
└── ListOfHosts.csv</pre>
</div></div>



<h3 class="wp-block-heading">Web Server In Action</h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="464" height="408" src="https://www.virtjunkie.com/wp-content/uploads/2020/04/image-1.png" alt="" class="wp-image-1159" srcset="/wp-content/uploads/2020/04/image-1.png 464w, /wp-content/uploads/2020/04/image-1-300x264.png 300w" sizes="(max-width: 464px) 100vw, 464px" /></figure>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<h2 class="wp-block-heading">Create ISO</h2>



<p>This is the process to create a custom ISO</p>
</div></div>



<pre class="urvanov-syntax-highlighter-plain-tag">genisoimage -relaxed-filenames -J -R -o &amp;#91;yourisoname].iso -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e efiboot.img -no-emul-boot &amp;#91;path to extracted iso]</pre>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<h2 class="wp-block-heading">References</h2>



<ul><li>I owe a big thank you to Andrew Dauncey (<a rel="noreferrer noopener" href="https://twitter.com/daunce_" target="_blank">twitter</a>, <a rel="noreferrer noopener" href="https://theoddangryshot.com/" target="_blank">blog</a>, <a rel="noreferrer noopener" href="https://github.com/daunce" target="_blank">github</a>). He created <a rel="noreferrer noopener" href="https://theoddangryshot.com/2016/09/07/esxi-kickstart-with-python/" target="_blank">a post</a> back in 2016 that accomplished something similar to this, but was no longer working with modern versions of vSphere. I updated the code to work with vSphere, and added some additional functionality. Thanks again Andrew!</li><li>As always, the VMware documentation is a good place to start. Here&#8217;s the documentation for 6.7 (<a rel="noreferrer noopener" href="https://docs.vmware.com/en/VMware-vSphere/6.7/com.vmware.esxi.upgrade.doc/GUID-870A07BC-F8B4-47AF-9476-D542BA53F1F5.html" target="_blank">link</a>) and here&#8217;s the documentation for 7.0 (<a href="https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.esxi.upgrade.doc/GUID-870A07BC-F8B4-47AF-9476-D542BA53F1F5.html" target="_blank" rel="noreferrer noopener">link</a>)</li></ul>
</div></div>



<p></p>
<p>The post <a href="/2020/04/09/poor-mans-autodeploy/">Poor Man&#8217;s AutoDeploy Using Custom Kickstart, and Python</a> appeared first on <a href="/">VirtJunkie</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>/2020/04/09/poor-mans-autodeploy/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
