{"id":14904,"date":"2019-12-06T16:31:03","date_gmt":"2019-12-06T16:31:03","guid":{"rendered":"https:\/\/ushipblogsubd.wpengine.com\/?p=14904"},"modified":"2025-09-03T15:07:18","modified_gmt":"2025-09-03T15:07:18","slug":"effortless-ami-deployments-with-chef-infra-and-habitat-part-2","status":"publish","type":"post","link":"https:\/\/ushipblogsubd.wpengine.com\/company-news\/effortless-ami-deployments-with-chef-infra-and-habitat-part-2\/","title":{"rendered":"Effortless AMI Deployments with Chef Infra and Habitat &#8211; Part 2"},"content":{"rendered":"<p>This is Part 2 of a series. Please make sure and read\u00a0Part 1\u00a0before continuing.<\/p>\n<p>Deploying Habitat<\/p>\n<p>In Part 1 of this series, we generated a new &#8220;webserver&#8221; cookbook, built a Habitat package with it and then pushed that to the\u00a0Habitat Builder. Now, we&#8217;re going to deploy a Windows server on Amazon Web Services. This server will load our Habitat package when it&#8217;s created and after it runs then we should have the default IIS site running.<\/p>\n<p>The first thing we need to do is login to the AWS Management Console and go to the EC2 Dashboard:<\/p>\n<p>Click on &#8220;Launch instance&#8221; which will take us to the wizard for launching a server.<\/p>\n<p>Search or scroll down to the image &#8220;Microsoft Windows Server 2012 R2 Base&#8221; and click &#8220;Select&#8221; to go to the next screen.<\/p>\n<p>Select an instance size for your server. I&#8217;ll use t2.micro to stay in the AWS free tier.<\/p>\n<p>Click the &#8220;Next: Configure Instance Details&#8221; button. On the next page, select a VPC or create a new one if you don&#8217;t have one already then scroll to the bottom and the following to the &#8220;User data&#8221; under the &#8220;Advanced Details&#8221; and click &#8220;Next: Add Storage&#8221;<\/p>\n<p>&amp;lt;powershell&amp;gt;<br \/>\nStart-Transcript<br \/>\n# Install Habitat<br \/>\nif ((Get-Command &#8220;hab&#8221; -ErrorAction SilentlyContinue)) {<br \/>\n    Write-Host &#8220;Habitat Installation found&#8221;<br \/>\n} else {<br \/>\n    Write-Host &#8220;Habitat Installation not found, installing&#8230;&#8221;<br \/>\n    (New-Object System.Net.WebClient).DownloadString(&#8216;https:\/\/raw.githubusercontent.com\/habitat-sh\/habitat\/master\/components\/hab\/install.ps1&#8217;) | Out-File install.ps1<br \/>\n    # Install Habitat<br \/>\n    if (Test-Path -Path env:HAB_VERSION) {<br \/>\n        .\\install.ps1 -Version $env:HAB_VERSION<br \/>\n    } else {<br \/>\n        .\\install.ps1<br \/>\n    }<br \/>\n}<\/p>\n<p>if (!(Test-Path -Path env:HAB_LICENSE)) {<br \/>\n    $env:HAB_LICENSE=&#8221;accept-no-persist&#8221;<br \/>\n}<\/p>\n<p># Install supervisor and Habitat Windows Service<br \/>\nWrite-Host &#8220;Installing Habitat Supervisor and Windows Service&#8230;&#8221;<br \/>\nhab pkg install core\/hab-sup<br \/>\nhab pkg install core\/windows-service<br \/>\nhab pkg exec core\/windows-service install<br \/>\n[System.Environment]::SetEnvironmentVariable(&#8220;HAB_LICENSE&#8221;, &#8220;accept&#8221;, [System.EnvironmentVariableTarget]::Machine)<\/p>\n<p>Write-Host &#8220;Finished Installing Habitat Supervisor and Windows Service&#8221;<\/p>\n<p>Start-Service -Name &#8220;Habitat&#8221;<\/p>\n<p>Write-Host &#8220;Installing webserver package&#8221;<br \/>\nC:\\ProgramData\\Habitat\\hab.exe pkg install uship\/webserver<br \/>\nWrite-Host &#8220;webserver package installed&#8221;<br \/>\nWrite-Host &#8220;Loading webserver service&#8221;<br \/>\nC:\\ProgramData\\Habitat\\hab.exe svc load uship\/webserver<br \/>\nWrite-Host &#8220;webserver service loaded&#8221;<br \/>\nStop-Transcript<br \/>\n&amp;lt;\/powershell&amp;gt;<\/p>\n<p>You can leave the default storage size or adjust it as needed and click &#8220;Next: Add Tags&#8221; to go to the next step. Feel free to add any tags that you&#8217;d like. I&#8217;m going to set a &#8220;Name&#8221; tag so I can easily find the server.<\/p>\n<p>On the next step, create a new security group or select an existing one. You&#8217;ll want one that has port 80 open and also 3389 if you want to be able to remote into it. Click on &#8220;Review and Launch&#8221; and make sure your settings are good. Click the &#8220;Launch&#8221; button to create the server and make sure to create or select a keypair before clicking the &#8220;Launch Instances&#8221; button. Launching the server will take a few minutes but after it&#8217;s up, grab the password, using the private key that corresponds to the keypair you selected at launch time, and login remotely to the instance.<\/p>\n<p>To make sure that everything worked properly, we&#8217;ll check a couple of things. First, go to the\u00a0C:\\Users\\Administrator\\Documents\u00a0directory and open the Powershell transcript.<\/p>\n<p>In the transcript, we can see the Habitat installation, starting the Habitat service, and then loading the webserver package. To check that the Chef run completed successfully, open the\u00a0Habitat.log\u00a0file from the\u00a0C:\\hab\\svc\\windows-service\\logs\u00a0directory. You can see it loading the Habitat supervisor and then running the Chef Client:<\/p>\n<p>2019-11-21 19:33:33,806 &#8211; Habitat windows service is starting launcher at: C:\\hab\\pkgs\\core\\hab-launcher\\12605\\20191112144934\\bin\\hab-launch.exe<br \/>\n2019-11-21 19:33:33,816 &#8211; Habitat windows service is starting launcher with args: run &#8211;no-color<br \/>\n2019-11-21 19:33:34,216 &#8211; hab-sup(MR): core\/hab-sup (core\/hab-sup\/0.90.6\/20191112145002)<br \/>\n2019-11-21 19:33:34,216 &#8211; hab-sup(MR): Supervisor Member-ID efdc426fe81743deac99d168bbda512e<br \/>\n2019-11-21 19:33:34,216 &#8211; hab-sup(MR): Starting gossip-listener on 0.0.0.0:9638<br \/>\n2019-11-21 19:33:34,216 &#8211; hab-sup(MR): Starting ctl-gateway on 127.0.0.1:9632<br \/>\n2019-11-21 19:33:34,216 &#8211; hab-sup(MR): Starting http-gateway on 0.0.0.0:9631<br \/>\n2019-11-21 19:33:35,145 &#8211; Logging configuration file &#8216;C:\\hab\/sup\\default\\config\\log.yml&#8217; not found; using default logging configuration<br \/>\n2019-11-21 19:34:41,087 &#8211; hab-sup(AG): The uship\/webserver service was successfully loaded<br \/>\n2019-11-21 19:34:44,114 &#8211; hab-sup(MR): Starting uship\/webserver (uship\/webserver\/0.0.1\/20191115133545)<br \/>\n2019-11-21 19:34:44,137 &#8211; webserver.default(UCW): Watching user.toml<br \/>\n2019-11-21 19:34:44,153 &#8211; webserver.default(HK): Modified hook content in C:\\hab\\svc\\webserver\\hooks\\run<br \/>\n2019-11-21 19:34:44,154 &#8211; webserver.default(SR): Hooks recompiled<br \/>\n2019-11-21 19:34:44,166 &#8211; webserver.default(CF): Created configuration file C:\\hab\\svc\\webserver\\config\\attributes.json<br \/>\n2019-11-21 19:34:44,166 &#8211; webserver.default(CF): Created configuration file C:\\hab\\svc\\webserver\\config\\bootstrap-config.rb<br \/>\n2019-11-21 19:34:44,166 &#8211; webserver.default(CF): Created configuration file C:\\hab\\svc\\webserver\\config\\client-config.rb<br \/>\n2019-11-21 19:34:44,166 &#8211; webserver.default(SR): Initializing<br \/>\n2019-11-21 19:34:45,126 &#8211; webserver.default(SV): Starting service as user=win-3bdeq9ruckm$, group=&amp;lt;anonymous&amp;gt;<br \/>\n2019-11-21 19:34:56,767 &#8211; webserver.default(O): Starting Chef Client, version 14.11.21[0m<br \/>\n2019-11-21 19:35:02,230 &#8211; webserver.default(O): Using policy &#8216;webserver&#8217; at revision &#8216;835107fe240d0a571c9d2fc7450a88e208b0f04c5c5e8cbd3865c3838439d4b9&#8242;[0m<br \/>\n2019-11-21 19:35:02,236 &#8211; webserver.default(O): resolving cookbooks for run list: [&#8220;webserver::default@0.1.0 (b9bf53c)&#8221;][0m<br \/>\n2019-11-21 19:35:02,349 &#8211; webserver.default(O): Synchronizing Cookbooks:[0m<br \/>\n2019-11-21 19:35:02,535 &#8211; webserver.default(O):   &#8211; iis (7.2.0)[0m<br \/>\n2019-11-21 19:35:02,573 &#8211; webserver.default(O):   &#8211; webserver (0.1.0)[0m<br \/>\n2019-11-21 19:35:02,611 &#8211; webserver.default(O):   &#8211; windows (6.0.1)[0m<br \/>\n2019-11-21 19:35:02,611 &#8211; webserver.default(O): Installing Cookbook Gems:[0m<br \/>\n2019-11-21 19:35:02,639 &#8211; webserver.default(O): Compiling Cookbooks&#8230;[0m<br \/>\n2019-11-21 19:35:02,740 &#8211; webserver.default(O): Converging 2 resources[0m<br \/>\n2019-11-21 19:35:02,740 &#8211; webserver.default(O): Recipe: iis::default[0m<br \/>\n2019-11-21 19:35:02,763 &#8211; webserver.default(O):   * iis_install[install IIS] action install<br \/>\n2019-11-21 19:35:02,764 &#8211; webserver.default(O):     * windows_feature[IIS-WebServerRole] action install<br \/>\n2019-11-21 19:35:49,670 &#8211; webserver.default(O):       * windows_feature_dism[IIS-WebServerRole] action install<br \/>\n2019-11-21 19:35:49,670 &#8211; webserver.default(O):         [32m- install Windows feature iis-webserverrole[0m<br \/>\n2019-11-21 19:35:49,670 &#8211; webserver.default(O): [0m<br \/>\n2019-11-21 19:35:49,670 &#8211; webserver.default(O): [0m<br \/>\n2019-11-21 19:35:51,202 &#8211; webserver.default(O): [0m  * windows_service[iis] action enable (up to date)<br \/>\n2019-11-21 19:35:51,383 &#8211; webserver.default(O):   * windows_service[iis] action start (up to date)<br \/>\n2019-11-21 19:35:51,427 &#8211; webserver.default(O): [0m<br \/>\n2019-11-21 19:35:51,427 &#8211; webserver.default(O): Running handlers:[0m<br \/>\n2019-11-21 19:35:51,427 &#8211; webserver.default(O): Running handlers complete<br \/>\n2019-11-21 19:35:51,433 &#8211; webserver.default(O): [0mChef Client finished, 3\/5 resources updated in 54 seconds[0m<\/p>\n<p>&amp;nbsp;<\/p>\n<p>We can see that Chef ran the\u00a0iis::default\u00a0recipe to install IIS and start the service. Let&#8217;s go to the IP address of the instance and you can see the default IIS site:<\/p>\n<p>At this point, we&#8217;ve shown how we can leverage Habitat and Powershell user data to bring up a server and configure it without having to fully\u00a0bootstrap\u00a0it. In Part 3 of this series, we&#8217;ll look at how we can utilize the Parameter Store in AWS Systems Manager to handle dynamic configuration that was traditionally kept in\u00a0Chef Vault\u00a0or\u00a0Data Bags.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is Part 2 of a series. Please make sure and read\u00a0Part 1\u00a0before continuing. Deploying Habitat In Part 1 of this series, we generated a new &#8220;webserver&#8221; cookbook, built a Habitat package with it and then pushed that to the\u00a0Habitat Builder. Now, we&#8217;re going to deploy a Windows server on Amazon Web Services. This server&#8230;<a class=\"read-more\" href=\"https:\/\/ushipblogsubd.wpengine.com\/company-news\/effortless-ami-deployments-with-chef-infra-and-habitat-part-2\/\"> Read More<\/a><\/p>\n","protected":false},"author":51,"featured_media":14946,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[297],"class_list":["post-14904","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-company-news","tag-shipping-code"],"acf":{"blog_post_content":null},"_links":{"self":[{"href":"https:\/\/ushipblogsubd.wpengine.com\/wp-json\/wp\/v2\/posts\/14904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ushipblogsubd.wpengine.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ushipblogsubd.wpengine.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ushipblogsubd.wpengine.com\/wp-json\/wp\/v2\/users\/51"}],"replies":[{"embeddable":true,"href":"https:\/\/ushipblogsubd.wpengine.com\/wp-json\/wp\/v2\/comments?post=14904"}],"version-history":[{"count":0,"href":"https:\/\/ushipblogsubd.wpengine.com\/wp-json\/wp\/v2\/posts\/14904\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ushipblogsubd.wpengine.com\/wp-json\/wp\/v2\/media\/14946"}],"wp:attachment":[{"href":"https:\/\/ushipblogsubd.wpengine.com\/wp-json\/wp\/v2\/media?parent=14904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ushipblogsubd.wpengine.com\/wp-json\/wp\/v2\/categories?post=14904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ushipblogsubd.wpengine.com\/wp-json\/wp\/v2\/tags?post=14904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}