<?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>Packer Archives - VirtJunkie</title>
	<atom:link href="/category/automation/hashicorp/packer/feed/" rel="self" type="application/rss+xml" />
	<link>/category/automation/hashicorp/packer/</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>Packer Archives - VirtJunkie</title>
	<link>/category/automation/hashicorp/packer/</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-667f6dd60b359410829469" 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-667f6dd60b367531559530" 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-667f6dd60b36b033447964" 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-667f6dd60b36d869042039" 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-667f6dd60b36e077529997" 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-667f6dd60b36f696509176" 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-667f6dd60b370848518098" 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-667f6dd60b372660831910" 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>VMware Template Management using Hashicorp Packer</title>
		<link>/2020/03/23/vmware-template-packer/</link>
					<comments>/2020/03/23/vmware-template-packer/#comments</comments>
		
		<dc:creator><![CDATA[Jon]]></dc:creator>
		<pubDate>Mon, 23 Mar 2020 13:00:00 +0000</pubDate>
				<category><![CDATA[Automation]]></category>
		<category><![CDATA[Packer]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[VMware]]></category>
		<guid isPermaLink="false">http://www.virtjunkie.com/?p=964</guid>

					<description><![CDATA[<p>VMware Templates: they make life amazing, don’t they? Initial creation of a template isn’t too hard, but there are downsides. In this article, I will talk about the downsides of traditional enterprise template management, how Packer can help, and give examples (and code!) for creating Windows and Linux templates in VMware vCenter using Packer.</p>
<p>The post <a href="/2020/03/23/vmware-template-packer/">VMware Template Management using Hashicorp Packer</a> appeared first on <a href="/">VirtJunkie</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="has-text-align-left">VMware Templates: they make life amazing, don&#8217;t they? Creating a your first vSphere template is easy, but there are limitations when using them in enterprise environments. In this article, I will talk about the downsides of traditional enterprise template management, how Packer can help, and give examples (and code!) for creating Windows and Linux templates in VMware vCenter using Packer. </p>



<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">Traditional Enterprise Template Management</h2>



<ol><li>Templates Across Multiple Sites &#8211; create a master template and replicate to ensure the same state exists<ol><li>Introduces operational complexity</li><li>Extends the total amount of time it takes to patch all templates</li></ol></li><li>OS and Application updates need to be performed for every application on every template<ol><li>Repetition sucks!</li><li>Introduces risk due to <a rel="noreferrer noopener" aria-label="C2K errors (opens in a new tab)" href="https://www.lifewire.com/have-you-been-the-butt-of-a-tech-joke-2619218" target="_blank">C2K errors</a></li></ol></li><li>Template creation ends up being a work of art.<ol><li>Individuals sometimes spend years fine-tuning all of the customization in a windows template.</li><li>On-boarding time is significantly increased</li><li>Projects delivered by third parties will take extra time to complete projects, as reverse engineering will need to occur in templates</li></ol></li><li>Documentation? Do you have it for your Windows and Linux Template?</li></ol>
</div></div>



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



<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">Enterprise Template Management With Packer</h2>



<ol><li>You are no longer limited to VMware! The effort used to create the template code can be used to create templates in other hypervisors, and in the cloud</li><li>Create net-new templates consistently, eliminating the old method of creating one template, and copying that to data-centers over the world.</li><li>Packer defines every configured setting and change for templates in code. Documentation: Check!</li><li>Changes to your templates make it into the wild faster and with zero configuration drift.</li></ol>
</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">Source Code</h2>



<p>You can find source code for Windows 2019, Windows 2016, and Ubuntu 18 in my GitHub repository: <a href="https://github.com/jonhowe/Virtjunkie.com/tree/master/Packer">https://github.com/jonhowe/Virtjunkie.com/tree/master/Packer</a></p>



<p>The remainder of this post will explain how this code works.</p>
</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">Packer Intro</h2>



<p>First and foremost, this is not a packer tutorial. Packer actually <a rel="noreferrer noopener" aria-label="provides an excellent getting started guide (opens in a new tab)" href="https://packer.io/intro/getting-started/install.html" target="_blank">provides an excellent getting started guide</a>. I&#8217;d actually recommend you start there if you have no background with packer. That said, I will blaze through a few concepts.</p>



<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">Packer Template File &amp; User Variables</h2>



<p>Packer stores it&#8217;s configuration in JSON files and calls them Packer Templates. There are two types of files. Master packer templates, and user variable files. Both are stored in JSON. The easiest way to think of this is the master packer template file contains properties that will be used as a part of the build. The user variable file (that is specified when you actually execute the build.. more on this later) in JSON format provides the values to the properties.</p>
</div></div>



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



<p>Hashicorp defines builders as:</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p><em>Builders are responsible for creating machines and generating images from them for various platforms. For example, there are separate builders for EC2, VMware, VirtualBox, etc. Packer comes with many builders by default, and can also be extended to add new builders.</em></p></blockquote>



<p>We will be using the builder called <a rel="noreferrer noopener" aria-label="VSphere-ISO (opens in a new tab)" href="https://packer.io/docs/builders/vsphere-iso.html" target="_blank">VSphere-ISO</a>.  This builder communicates directly with the vCenter API, which also makes this relevant for <a rel="noreferrer noopener" aria-label="VMC on AWS (opens in a new tab)" href="https://cloud.vmware.com/vmc-aws" target="_blank">VMC on AWS</a>.</p>
</div></div>



<h3 class="wp-block-heading">Attaching ISOs and Floppy Images</h3>



<p>Packer allows us to attach both <a rel="noreferrer noopener" aria-label="ISOs (opens in a new tab)" href="https://packer.io/docs/builders/vsphere-iso.html#iso_paths" target="_blank">ISOs</a> and <a rel="noreferrer noopener" aria-label="Floppy images (opens in a new tab)" href="https://packer.io/docs/builders/vsphere-iso.html#floppy-configuration" target="_blank">Floppy images</a> to the VM we are working with. </p>



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



<p>You can attach multiple ISOs to an image. For example, you can attach a Windows installer ISO, as well as a VMware tools ISO to a Windows VM. Here&#8217;s an example of how this works:</p>



<pre class="urvanov-syntax-highlighter-plain-tag">&quot;iso_paths&quot;: [
    &quot;[esxi1-nvme] ISO/Windows/14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_EN-US.ISO&quot;,
    &quot;[esxi1-nvme] ISO/VMTools/VMware-tools-windows-11.0.1-14773994.iso&quot;
]</pre>



<h4 class="wp-block-heading">Floppy Images</h4>



<p>Packer gives us the ability to take a file, a directory, or a floppy image, and present it to the target VM as a floppy image. This is very useful if you want to copy scripts to the VM to be executed locally. Here&#8217;s an example of how this works:</p>



<pre class="urvanov-syntax-highlighter-plain-tag">&quot;floppy_files&quot;: [
    &quot;./autounattend.xml&quot;,
    &quot;Scripts/vmtools.cmd&quot;,
    &quot;Scripts/level0-setup.ps1&quot;
]</pre>



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



<p><a rel="noreferrer noopener" aria-label="Communicators (opens in a new tab)" href="https://packer.io/docs/communicators/index.html" target="_blank">Communicators</a> are the mechanism Packer uses to upload files, execute scripts,  after the machine is created. Packer uses WinRM and SSH communicators. More on this later.</p>



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



<p>Provisioners are used to handle post image creation tasks, such as OS Customization and installing updates. Provisioners require communicators. In this case, the WinRM communicator will be used with Windows Images, while the SSH communicator will be used to communicate with Linux. We will be using the following provisioners:</p>



<figure class="wp-block-table"><table class=""><thead><tr><th class="has-text-align-left" data-align="left">Provisioner Name</th><th class="has-text-align-left" data-align="left">Used For</th></tr></thead><tbody><tr><td class="has-text-align-left" data-align="left"><a href="https://packer.io/docs/provisioners/powershell.html" target="_blank" rel="noreferrer noopener" aria-label="Powershell (opens in a new tab)">Powershell</a></td><td class="has-text-align-left" data-align="left">Performing all OS Customization Steps in Windows Images</td></tr><tr><td class="has-text-align-left" data-align="left"><a href="https://packer.io/docs/provisioners/windows-restart.html" target="_blank" rel="noreferrer noopener" aria-label="Windows-Restart (opens in a new tab)">Windows-Restart</a></td><td class="has-text-align-left" data-align="left">Restart Windows Images</td></tr><tr><td class="has-text-align-left" data-align="left"><a href="https://github.com/rgl/packer-provisioner-windows-update" target="_blank" rel="noreferrer noopener" aria-label="Windows-Update (opens in a new tab)">Windows-Update</a></td><td class="has-text-align-left" data-align="left">Apply Windows updates (community supported)</td></tr><tr><td class="has-text-align-left" data-align="left"><a href="https://packer.io/docs/provisioners/shell.html" target="_blank" rel="noreferrer noopener" aria-label="Shell (opens in a new tab)">Shell</a></td><td class="has-text-align-left" data-align="left">Used to install updates on Linux machines. We also set a custom &#8220;execution_command&#8221; that will allow for sudo to be used for all commands.</td></tr></tbody></table></figure>
</div></div>



<h2 class="wp-block-heading">Linux Templates</h2>



<p>Linux templates are pretty straight forward. Being born in open source, they are much easier to automate than Windows. Debian based distributions use a preseed file to silently execute the build. We will use packer to do the following:</p>



<ol><li>Create a blank VM</li><li>Attach Linux installer ISO</li><li>Create and attach media that has preseed.cfg file to the newly created image</li><li>Start VM</li><li>Send commands to the running VM via USB emulation to tell the Ubuntu installer to use the preseed.cfg file</li><li>Update all packages on the template</li><li>Shut Down VM</li><li>Mark as Template</li></ol>



<p>Here&#8217;s the directory structure:</p>



<pre class="urvanov-syntax-highlighter-plain-tag">Ubuntu18/
 ├── preseed.cfg
 ├── ubuntu-18.04.json
 └── ubuntu-vars.json
 0 directories, 3 files</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">Windows Templates</h2>



<p>Most consumers of Packer are using it to manage Linux images, but I rarely hear about managing Windows images. Windows has a bit more moving parts that cause more complexity. It was way harder for me to figure out, even with a couple of great posts I&#8217;ll list in the reference area. In order to have a complete windows template, we will need to achieve the following steps:</p>



<ol><li>Create a blank VM</li><li>Attach Windows Installer and VMware Tools ISO</li><li>Attach floppy image that contains scripts and autounattend.xml</li><li>Start VM</li><li>Silently Install Windows Server (windowsPE pass in Autounattend.xml)</li><li>Install VMware Tools (Specialize pass in Autounattend.xml executes vmtools.cmd)</li><li>Configure WinRM (oobeSystem pass in Autounattend.xml executes level0-setup.ps1)</li><li>Perform OS Customization (Packer PowerShell provisioner executes level1-setup.ps1)</li><li>Install Windows Updates (Packer Windows Update provisioner applies updates)</li><li>Shut Down VM</li><li>Mark as Template</li></ol>



<p>Definitely more complex than Linux, eh? Don&#8217;t worry though. I&#8217;ll do my best to add some value on top of documentation and blog articles that are out there. Here&#8217;s the directory structure:</p>



<pre class="urvanov-syntax-highlighter-plain-tag">WS19
 ├── autounattend.xml
 ├── Scripts
 │&amp;nbsp;&amp;nbsp; ├── level0-setup.ps1
 │&amp;nbsp;&amp;nbsp; ├── level1-setup.ps1
 │&amp;nbsp;&amp;nbsp; └── vmtools.cmd
 ├── vars-ws19.json
 └── ws19.json
 1 directory, 6 files</pre>
</div></div>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<h3 class="wp-block-heading">Autounattend.xml</h3>



<p>Microsoft allows us to provide an answer file to the Windows installer to achieve a silent install of Windows Server. The installer will look in all attached media to find a file named Autounattend.xml. This file contains a number of settings that are explained in a decent amount of detail on this <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/how-configuration-passes-work" target="_blank">Microsoft documentation page</a>. Below is a high level overview of the passes and how we are using them.<br><br>I found <a rel="noreferrer noopener" aria-label="this page helpful (opens in a new tab)" href="https://www.windowsafg.com/server2016.html" target="_blank">this page helpful</a> in creating the skeleton of the XML file.</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-2 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-vertically-aligned-center is-layout-flow wp-block-column-is-layout-flow">
<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" src="https://new.virtjunkie.com/wp-content/uploads/2020/03/dep-win8-l-configpassesandexes.jpg" alt="" class="wp-image-1005" width="610" height="341" srcset="/wp-content/uploads/2020/03/dep-win8-l-configpassesandexes.jpg 610w, /wp-content/uploads/2020/03/dep-win8-l-configpassesandexes-300x168.jpg 300w" sizes="(max-width: 610px) 100vw, 610px" /></figure>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<h4 class="wp-block-heading"><strong>windowsPE</strong></h4>



<ul><li>Select disk format</li><li>Select the OS Image (Core, GUI, Datacenter, Standard)</li><li>Add the product key (we&#8217;ll be using the 6 month trial)</li><li>Select Locale, Name, Organization</li></ul>
</div></div>



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



<ul><li>This configuration pass is used to apply updates, drivers, or language packs to a Windows image.</li></ul>
</div></div>



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



<ul><li>We are setting the <a rel="noreferrer noopener" href="https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-security-spp-skiprearm" target="_blank">property SkipRearm</a></li><li>Resets the SID</li></ul>
</div></div>



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



<ul><li>This configuration pass is used to create and configure information in the Windows image, and is specific to the hardware that the Windows image is installing to.</li><li>Install VMware Tools by executing (vmtools.cmd) in this step to ensure it&#8217;s available ASAP for Packer to perform the rest of template configuration steps</li><li>Computer name is set</li><li>Reboots the machine</li></ul>
</div></div>



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



<ul><li>Add user, set password</li><li>Execute powershell script (level0-setup.ps1) to enable WinRM, which is required for Packer provisioning</li></ul>
</div></div>
</div>
</div>
</div></div>



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



<p>Here are a few examples of how the script works</p>



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



<p>The command below will create a windows template with the following details.</p>



<figure class="wp-block-table"><table class=""><tbody><tr><td>Username</td><td>Administrator</td></tr><tr><td>Password</td><td>VMware1!</td></tr><tr><td>Additional User</td><td>Labadmin</td></tr></tbody></table></figure>



<p>If you want to change the password, you will need to specify it both in the vars file, as well as the autounattend.xml. The section you will change looks like this:</p>



<pre class="urvanov-syntax-highlighter-plain-tag">&amp;lt;UserAccounts&gt;
    &amp;lt;AdministratorPassword&gt;
        &amp;lt;Value&gt;VMware1!&amp;lt;/Value&gt;
        &amp;lt;PlainText&gt;true&amp;lt;/PlainText&gt;
    &amp;lt;/AdministratorPassword&gt;
    &amp;lt;LocalAccounts&gt;
        &amp;lt;LocalAccount wcm:action=&quot;add&quot;&gt;
            &amp;lt;Description&gt;Lab Administrator&amp;lt;/Description&gt;
            &amp;lt;DisplayName&gt;labadmin&amp;lt;/DisplayName&gt;
            &amp;lt;Group&gt;Administrators&amp;lt;/Group&gt;
            &amp;lt;Name&gt;labadmin&amp;lt;/Name&gt;
        &amp;lt;/LocalAccount&gt;
    &amp;lt;/LocalAccounts&gt;
&amp;lt;/UserAccounts&gt;
&amp;lt;AutoLogon&gt;
    &amp;lt;Password&gt;
        &amp;lt;Value&gt;VMware1!&amp;lt;/Value&gt;
        &amp;lt;PlainText&gt;true&amp;lt;/PlainText&gt;
    &amp;lt;/Password&gt;
    &amp;lt;Enabled&gt;true&amp;lt;/Enabled&gt;
    &amp;lt;Username&gt;Administrator&amp;lt;/Username&gt;
&amp;lt;/AutoLogon&gt;</pre>



<h4 class="wp-block-heading">In Action</h4>



<pre class="urvanov-syntax-highlighter-plain-tag">packer build -var-file vars-ws19.json ws19.json
vsphere-iso: output will be in this color.

==&gt; vsphere-iso: Creating VM...
==&gt; vsphere-iso: Customizing hardware...
==&gt; vsphere-iso: Mounting ISO images...
==&gt; vsphere-iso: Creating floppy disk...
    vsphere-iso: Copying files flatly from floppy_files
    vsphere-iso: Copying file: ./autounattend.xml
    vsphere-iso: Copying file: Scripts/vmtools.cmd
    vsphere-iso: Copying file: Scripts/level0-setup.ps1
    vsphere-iso: Done copying files from floppy_files
    vsphere-iso: Collecting paths from floppy_dirs
    vsphere-iso: Resulting paths from floppy_dirs : []
    vsphere-iso: Done copying paths from floppy_dirs
==&gt; vsphere-iso: Uploading created floppy image
==&gt; vsphere-iso: Adding generated Floppy...
==&gt; vsphere-iso: Set boot order...
==&gt; vsphere-iso: Power on VM...
==&gt; vsphere-iso: Waiting for IP...
==&gt; vsphere-iso: IP address: 172.16.1.73
==&gt; vsphere-iso: Using winrm communicator to connect: 172.16.1.73
==&gt; vsphere-iso: Waiting for WinRM to become available...
    vsphere-iso: WinRM connected.
==&gt; vsphere-iso: #&amp;lt; CLIXML
==&gt; vsphere-iso: &amp;lt;Objs Version=&quot;1.1.0.1&quot; xmlns=&quot;http://schemas.microsoft.com/powershell/2004/04&quot;&gt;&amp;lt;Obj S=&quot;progress&quot; RefId=&quot;0&quot;&gt;&amp;lt;TN RefId=&quot;0&quot;&gt;&amp;lt;T&gt;System.Management.Automation.PSCustomObject&amp;lt;/T&gt;&amp;lt;T&gt;System.Object&amp;lt;/T&gt;&amp;lt;/TN&gt;&amp;lt;MS&gt;&amp;lt;I64 N=&quot;SourceId&quot;&gt;1&amp;lt;/I64&gt;&amp;lt;PR N=&quot;Record&quot;&gt;&amp;lt;AV&gt;Preparing modules for first use.&amp;lt;/AV&gt;&amp;lt;AI&gt;0&amp;lt;/AI&gt;&amp;lt;Nil /&gt;&amp;lt;PI&gt;-1&amp;lt;/PI&gt;&amp;lt;PC&gt;-1&amp;lt;/PC&gt;&amp;lt;T&gt;Completed&amp;lt;/T&gt;&amp;lt;SR&gt;-1&amp;lt;/SR&gt;&amp;lt;SD&gt; &amp;lt;/SD&gt;&amp;lt;/PR&gt;&amp;lt;/MS&gt;&amp;lt;/Obj&gt;&amp;lt;Obj S=&quot;progress&quot; RefId=&quot;1&quot;&gt;&amp;lt;TNRef RefId=&quot;0&quot; /&gt;&amp;lt;MS&gt;&amp;lt;I64 N=&quot;SourceId&quot;&gt;1&amp;lt;/I64&gt;&amp;lt;PR N=&quot;Record&quot;&gt;&amp;lt;AV&gt;Preparing modules for first use.&amp;lt;/AV&gt;&amp;lt;AI&gt;0&amp;lt;/AI&gt;&amp;lt;Nil /&gt;&amp;lt;PI&gt;-1&amp;lt;/PI&gt;&amp;lt;PC&gt;-1&amp;lt;/PC&gt;&amp;lt;T&gt;Completed&amp;lt;/T&gt;&amp;lt;SR&gt;-1&amp;lt;/SR&gt;&amp;lt;SD&gt; &amp;lt;/SD&gt;&amp;lt;/PR&gt;&amp;lt;/MS&gt;&amp;lt;/Obj&gt;&amp;lt;/Objs&gt;
==&gt; vsphere-iso: Connected to WinRM!
==&gt; vsphere-iso: Provisioning with Powershell...
==&gt; vsphere-iso: Provisioning with powershell script: Scripts/level1-setup.ps1
    vsphere-iso:
    vsphere-iso:
    vsphere-iso:     Directory: C:\Users\Administrator\Documents\WindowsPowerShell
    vsphere-iso:
    vsphere-iso:
    vsphere-iso: Mode                LastWriteTime         Length Name
    vsphere-iso: ----                -------------         ------ ----
    vsphere-iso: -a----        3/22/2020   3:02 PM              0 Microsoft.PowerShell_profile.ps1
==&gt; vsphere-iso: Restarting Machine
==&gt; vsphere-iso: Waiting for machine to restart...
==&gt; vsphere-iso: A system shutdown is in progress.(1115)
==&gt; vsphere-iso: #&amp;lt; CLIXML
    vsphere-iso: WS19-TPL restarted.
==&gt; vsphere-iso: &amp;lt;Objs Version=&quot;1.1.0.1&quot; xmlns=&quot;http://schemas.microsoft.com/powershell/2004/04&quot;&gt;&amp;lt;Obj S=&quot;progress&quot; RefId=&quot;0&quot;&gt;&amp;lt;TN RefId=&quot;0&quot;&gt;&amp;lt;T&gt;System.Management.Automation.PSCustomObject&amp;lt;/T&gt;&amp;lt;T&gt;System.Object&amp;lt;/T&gt;&amp;lt;/TN&gt;&amp;lt;MS&gt;&amp;lt;I64 N=&quot;SourceId&quot;&gt;1&amp;lt;/I64&gt;&amp;lt;PR N=&quot;Record&quot;&gt;&amp;lt;AV&gt;Preparing modules for first use.&amp;lt;/AV&gt;&amp;lt;AI&gt;0&amp;lt;/AI&gt;&amp;lt;Nil /&gt;&amp;lt;PI&gt;-1&amp;lt;/PI&gt;&amp;lt;PC&gt;-1&amp;lt;/PC&gt;&amp;lt;T&gt;Completed&amp;lt;/T&gt;&amp;lt;SR&gt;-1&amp;lt;/SR&gt;&amp;lt;SD&gt; &amp;lt;/SD&gt;&amp;lt;/PR&gt;&amp;lt;/MS&gt;&amp;lt;/Obj&gt;&amp;lt;Obj S=&quot;progress&quot; RefId=&quot;1&quot;&gt;&amp;lt;TNRef RefId=&quot;0&quot; /&gt;&amp;lt;MS&gt;&amp;lt;I64 N=&quot;SourceId&quot;&gt;2&amp;lt;/I64&gt;&amp;lt;PR N=&quot;Record&quot;&gt;&amp;lt;AV&gt;Preparing modules for first use.&amp;lt;/AV&gt;&amp;lt;AI&gt;0&amp;lt;/AI&gt;&amp;lt;Nil /&gt;&amp;lt;PI&gt;-1&amp;lt;/PI&gt;&amp;lt;PC&gt;-1&amp;lt;/PC&gt;&amp;lt;T&gt;Completed&amp;lt;/T&gt;&amp;lt;SR&gt;-1&amp;lt;/SR&gt;&amp;lt;SD&gt; &amp;lt;/SD&gt;&amp;lt;/PR&gt;&amp;lt;/MS&gt;&amp;lt;/Obj&gt;&amp;lt;/Objs&gt;
==&gt; vsphere-iso: Machine successfully restarted, moving on
==&gt; vsphere-iso: Uploading the Windows update elevated script...
==&gt; vsphere-iso: Uploading the Windows update check for reboot required elevated script...
==&gt; vsphere-iso: Uploading the Windows update script...
==&gt; vsphere-iso: Running Windows update...
    vsphere-iso: Searching for Windows updates...
    vsphere-iso: Found Windows update (2018-10-15; 20.72 MB): Update for Adobe Flash Player for Windows Server 2019 (1809) for x64-based Systems (KB4462930)
    vsphere-iso: Found Windows update (2020-02-11; 20.75 MB): 2020-02 Security Update for Adobe Flash Player for Windows Server 2019 for x64-based Systems (KB4537759)
    vsphere-iso: Found Windows update (2020-02-25; 71.37 MB): 2020-02 Cumulative Update for .NET Framework 3.5, 4.7.2 and 4.8 for Windows Server 2019 for x64 (KB4538156)
    vsphere-iso: Found Windows update (2020-02-25; 2.34 MB): 2020-01 Update for Windows Server 2019 for x64-based Systems (KB4494174)
    vsphere-iso: Found Windows update (2020-03-10; 30.62 MB): Windows Malicious Software Removal Tool x64 - March 2020 (KB890830)
    vsphere-iso: Found Windows update (2020-03-22; 114.85 MB): Security Intelligence Update for Windows Defender Antivirus - KB2267602 (Version 1.311.1752.0)
    vsphere-iso: Found Windows update (2020-03-10; 15349.68 MB): 2020-03 Cumulative Update for Windows Server 2019 (1809) for x64-based Systems (KB4538461)
    vsphere-iso: Downloading Windows updates (7 updates; 15610.33 MB)...
    vsphere-iso: Waiting for operation to complete (system performance: 44% cpu; 31% memory)...
    vsphere-iso: Installing Windows updates...
    vsphere-iso: Waiting for operation to complete (system performance: 20% cpu; 41% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 51% cpu; 51% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 51% cpu; 50% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 50% cpu; 54% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 43% cpu; 55% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 0% cpu; 61% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 38% cpu; 52% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 63% cpu; 48% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 27% cpu; 46% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 45% cpu; 47% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 55% cpu; 46% memory)...
    vsphere-iso: Waiting for operation to complete (system performance: 53% cpu; 44% memory)...
    vsphere-iso: Waiting for the Windows Modules Installer to exit...
    vsphere-iso: Waiting for operation to complete (system performance: 81% cpu; 44% memory)...
==&gt; vsphere-iso: Restarting the machine...
==&gt; vsphere-iso: Waiting for machine to become available...
==&gt; vsphere-iso: A system shutdown is in progress.(1115)
==&gt; vsphere-iso: A system shutdown is in progress.(1115)
    vsphere-iso: Waiting for the Windows Modules Installer to exit...
    vsphere-iso: WS19-TPL restarted.
==&gt; vsphere-iso: Running Windows update...
    vsphere-iso: Searching for Windows updates...
    vsphere-iso: Found Windows update (2020-03-19; 4.91 MB): Update for Windows Defender Antivirus antimalware platform - KB4052623 (Version 4.18.2003.6)
    vsphere-iso: Downloading Windows updates (1 updates; 4.91 MB)...
    vsphere-iso: Installing Windows updates...
==&gt; vsphere-iso: Shut down VM...
==&gt; vsphere-iso: Deleting Floppy drives...
==&gt; vsphere-iso: Deleting Floppy image...
==&gt; vsphere-iso: Eject CD-ROM drives...
==&gt; vsphere-iso: Convert VM into template...
Build 'vsphere-iso' finished.

==&gt; Builds finished. The artifacts of successful builds are:
--&gt; vsphere-iso: WS19-TPL</pre>



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



<p>The command below will create a Ubuntu template with the following details:</p>



<figure class="wp-block-table"><table class=""><tbody><tr><td>Root Password</td><td>VMware1!</td></tr><tr><td>Additional Username (also added to sudoers)</td><td>jhowe</td></tr><tr><td>Additional username&#8217;s password</td><td>VMware1!</td></tr></tbody></table></figure>



<p>All of the above can be changed by modifying values in the preseed.cfg file.</p>



<h4 class="wp-block-heading">In Action</h4>



<pre class="urvanov-syntax-highlighter-plain-tag">packer build -var-file ubuntu-vars.json ubuntu-18.04.json

jhowe@jonlaptopalt:~/git/Personal/HomeLab/packer/Ubuntu18$ packer build -var-file ubuntu-vars.json ubuntu-18.04.json 
vsphere-iso: output will be in this color.

==&gt; vsphere-iso: Creating VM...
==&gt; vsphere-iso: Customizing hardware...
==&gt; vsphere-iso: Mounting ISO images...
==&gt; vsphere-iso: Creating floppy disk...
    vsphere-iso: Copying files flatly from floppy_files
    vsphere-iso: Copying file: ./preseed.cfg
    vsphere-iso: Done copying files from floppy_files
    vsphere-iso: Collecting paths from floppy_dirs
    vsphere-iso: Resulting paths from floppy_dirs : []
    vsphere-iso: Done copying paths from floppy_dirs
==&gt; vsphere-iso: Uploading created floppy image
==&gt; vsphere-iso: Adding generated Floppy...
==&gt; vsphere-iso: Set boot order...
==&gt; vsphere-iso: Power on VM...
==&gt; vsphere-iso: Waiting 10s for boot...
==&gt; vsphere-iso: Typing boot command...
==&gt; vsphere-iso: Waiting for IP...
==&gt; vsphere-iso: IP address: 172.16.1.72
==&gt; vsphere-iso: Using ssh communicator to connect: 172.16.1.72
==&gt; vsphere-iso: Waiting for SSH to become available...
==&gt; vsphere-iso: Connected to SSH!
==&gt; vsphere-iso: Provisioning with shell script: /tmp/packer-shell338854810
    vsphere-iso: Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
    vsphere-iso: Hit:2 http://us.archive.ubuntu.com/ubuntu bionic InRelease
    vsphere-iso: Hit:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease
    vsphere-iso: Hit:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
    vsphere-iso: Reading package lists...
    vsphere-iso: Reading package lists...
    vsphere-iso: Building dependency tree...
    vsphere-iso: Reading state information...
    vsphere-iso: Calculating upgrade...
    vsphere-iso: The following packages have been kept back:
    vsphere-iso:   linux-generic linux-headers-generic linux-image-generic
    vsphere-iso: The following packages will be upgraded:
    vsphere-iso:   dmidecode gcc-8-base libdrm-common libdrm2 libgcc1 libicu60 libnss-systemd
    vsphere-iso:   libpam-systemd libsqlite3-0 libstdc++6 libsystemd0 libudev1 libxml2
    vsphere-iso:   linux-firmware rsync systemd systemd-sysv udev
    vsphere-iso: 18 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
    vsphere-iso: Need to get 89.7 MB of archives.
    vsphere-iso: After this operation, 572 kB of additional disk space will be used.
    vsphere-iso: Get:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 perl-modules-5.26 all 5.26.1-6ubuntu0.3 [2,763 kB]

[Omitted some output in order to save space. Apt is downloading new packages]

[Omitted some output in order to save space. Apt is unpacking packages]

[Omitted some output in order to save space. Apt is &quot;Setting up... all upgraded packages]

    vsphere-iso: Processing triggers for systemd (237-3ubuntu10.39) ...
    vsphere-iso: Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
    vsphere-iso: Processing triggers for dbus (1.12.2-1ubuntu1.1) ...
    vsphere-iso: Processing triggers for mime-support (3.60ubuntu1) ...
    vsphere-iso: Processing triggers for ureadahead (0.100.0-21) ...
    vsphere-iso: Processing triggers for install-info (6.5.0.dfsg.1-2) ...
    vsphere-iso: Processing triggers for libc-bin (2.27-3ubuntu1) ...
    vsphere-iso: Template Build Complete
==&gt; vsphere-iso: Shut down VM...
==&gt; vsphere-iso: Deleting Floppy drives...
==&gt; vsphere-iso: Deleting Floppy image...
==&gt; vsphere-iso: Eject CD-ROM drives...
==&gt; vsphere-iso: Convert VM into template...
Build 'vsphere-iso' finished.

==&gt; Builds finished. The artifacts of successful builds are:
--&gt; vsphere-iso: Ubuntu18</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>



<p>I did a lot of research as when getting this up and running. The following sites were helpful.</p>



<ul><li>This is an EXCELLENT blog. The article he created unfortunately didn&#8217;t work, but it got me started. Either way, it&#8217;s worth a look. (<a href="https://dteslya.engineer/automation/2018-12-20-creating_vm_templates_with_packer/">https://dteslya.engineer/automation/2018-12-20-creating_vm_templates_with_packer/</a>)</li><li>Official Packer Documentation (<a href="https://packer.io/docs/index.html">https://packer.io/docs/index.html</a>)</li></ul>
</div></div>
<p>The post <a href="/2020/03/23/vmware-template-packer/">VMware Template Management using Hashicorp Packer</a> appeared first on <a href="/">VirtJunkie</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>/2020/03/23/vmware-template-packer/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
