{"id":28,"date":"2019-05-21T05:13:00","date_gmt":"2019-05-21T05:13:00","guid":{"rendered":"https:\/\/opstree.com\/blog\/\/2019\/05\/21\/lets-get-started-with-packer\/"},"modified":"2025-11-22T12:40:16","modified_gmt":"2025-11-22T07:10:16","slug":"lets-get-started-with-packer","status":"publish","type":"post","link":"https:\/\/opstree.com\/blog\/2019\/05\/21\/lets-get-started-with-packer\/","title":{"rendered":"Lets Get Started With Packer"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\"><span style=\"font-size: small;\">In this blogpost, we will see how to get started with packer. We will cover installation, writing a template for creating AWS AMI. To get the basic understanding of how packer works, You can refer to our previous blog &#8220;Intro To Packer&#8221;.<\/span><\/div>\n<div dir=\"ltr\"><\/div>\n<div dir=\"ltr\" style=\"text-align: left;\"><strong><span style=\"font-size: small;\">Installation\u00a0 <\/span><span style=\"font-size: small;\"><br \/>\n<\/span><\/strong><\/div>\n<div dir=\"ltr\" style=\"text-align: left;\">\n<ol style=\"text-align: justify;\">\n<li><span style=\"font-size: small;\">Official method to download packer as precompiled binary, packer does not provide system packages and neither they have any plan to make it avail as such:-<\/span><span style=\"font-size: small;\">$curl -L<a style=\"text-decoration: none;\" href=\"https:\/\/releases.hashicorp.com\/packer\/1.4.0\/packer_1.4.0_linux_amd64.zip\" target=\"_blank\" rel=\"noopener\"> https:\/\/releases.hashicorp.com\/packer\/1.4.0\/packer_1.4.0_linux_amd64.zip<\/a><\/span><\/li>\n<li><span style=\"font-size: small;\">After downloading the binary unzip it to the location you want to keep it. If you want it to be installed such that it can be used by system-wide users, do \u00a0not unzip in user space $sudo unzip packer_1.4.0_linux_amd64.zip -d \/usr\/local\/packer\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">After unzipping the package, the directory should contain a single binary program called packer .<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">The final step to installation is to make sure the directory you installed Packer to is set on the PATH, so that it can be used using a command line. Open the \/etc\/environment and append the below line to the <span style=\"font-family: serif;\">end<\/span> of the file export PATH=&#8221;$PATH:\/usr\/local\/packer&#8221; After adding the line into the file to let the change reflect source the environment file $source \/etc\/environment\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">Verify the installation by firing packer command or simply check its version by \u00a0\u00a0 $packer &#8211;version . You should see the version of packer as an output.<\/span><\/li>\n<\/ol>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">Once installed, running packer is as simple as packer build , which will take the build-file and run the steps we provide within. Let\u2019s get started with a simple build file.<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">Setting Up Stage<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/iFIDb7Lq0s8ENZHEkjqb4_L8vczf1jdF2pOZUcBeFYcmqT0mZbDj0oT9O71XrqqFi5Yhq_tSnWYT5OwgeVMIR-9bpDw99n9Fe9XLI0H5KrNLjZdkgo2Bz5wynmUbyhHLpqf2WYqIHlxML0blFA\" width=\"400\" height=\"139\" \/> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">As we are building an image for AWS cloud, there are certain prerequisites which need to be taken care of. <\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">You should have IAM user who has access to create and destroy ec2 instance, create an AMI, create and destroy security groups etc. You can find sample IAM policy for packer user in <\/span><a style=\"text-decoration-line: none;\" href=\"https:\/\/gist.github.com\/MattSurabian\/5976061\" target=\"_blank\" rel=\"noopener\">sample minimum IAM user policy for Packer<\/a>.<\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">After setting up your IAM user for packer, generate the access key and id and save it.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">Now having noted the key, you can either directly use it in your template (which is not suggested) or you can configure it as an environment variable or the AWS CLI config on which you have the packer installed.<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">I have configured it with AWS CLI config so I did not have to define in variable section or in the builder section. You can also pass your access keys as variable as an option while running packer build command.<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">Here we will be installing apache webserver in the image. I have named this json file as httpd.json and used httpd.sh script to install httpd under provisioner section.<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/CkSC0quF8AWiOyH6jjEuUo8tu_A5chKoTef9Vqxzd0JaUW-LqIPqNW-FEXrIYKgUr77KfzSemhYWct5b-2i6vPi0DzQw957mtqZ4AVHzPf5BquNoWUxrO8yF39poaGEQk9nPV098hjrqsLsNTA\" width=\"400\" height=\"400\" \/><\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">Below is the sample httpd.json file<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"margin-left: 0; text-align: justify;\">\n<table style=\"border-collapse: collapse; margin-left: 0; margin-right: 0; text-align: left;\">\n<colgroup>\n<col width=\"624\" \/> <\/colgroup>\n<tbody>\n<tr style=\"height: 0;\">\n<td style=\"background-color: #19171c; padding: 5pt; vertical-align: top;\">\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\"><span style=\"font-size: small;\"><span style=\"color: #00ff00;\">{<\/span><\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\"><span style=\"font-size: small;\"><span style=\"font-size: small;\"><span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0 &#8220;variables&#8221;: {<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;ami_id&#8221;: &#8220;ami-0a574895390037a62&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;app_name&#8221;: &#8220;httpd&#8221;<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0},<\/span><\/span><\/span><span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0&#8220;builders&#8221;: [{<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;type&#8221;: &#8220;amazon-ebs&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;region&#8221;: &#8220;ap-south-1&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;vpc_id&#8221;: &#8220;vpc-df95d4b7&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;subnet_id&#8221;: &#8220;subnet-175b2d7f&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;source_ami&#8221;: &#8220;{{user `ami_id`}}&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;instance_type&#8221;: &#8220;t2.micro&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;ssh_username&#8221;: &#8220;ubuntu&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;ami_name&#8221;: &#8220;PACKER-DEMO-{{user `app_name` }}&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;tags&#8221;: {<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;Name&#8221;: &#8220;PACKER-DEMO-{{user `app_name` }}&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;Env&#8221;: &#8220;DEMO&#8221;<\/span><\/p>\n<p><span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0}],<\/span><\/p>\n<p><span style=\"color: #00ff00;\">\u00a0\u00a0&#8220;provisioners&#8221;: [<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0{<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;type&#8221;: &#8220;shell&#8221;,<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8220;script&#8221;: &#8220;httpd.sh&#8221;<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0\u00a0}<\/span><br \/>\n<span style=\"color: #00ff00;\">]<\/span><\/p>\n<p><span style=\"color: #00ff00;\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">Below is the simple httpd.sh<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"margin-left: 0; text-align: justify;\">\n<table style=\"border-collapse: collapse; margin-left: 0; margin-right: 0; text-align: left;\">\n<colgroup>\n<col width=\"624\" \/> <\/colgroup>\n<tbody>\n<tr style=\"height: 0;\">\n<td style=\"background-color: #19171c; padding: 5pt; vertical-align: top;\">\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\">\n<p><span style=\"font-size: small; color: #00ff00;\">#!\/bin\/bash<\/span><\/p>\n<p>sudo apt-get update<br \/>\nsudo apt-get install -y httpd<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">First Validate your template by firing below command:-<\/span><\/div>\n<div dir=\"ltr\" style=\"margin-left: 0; text-align: justify;\">\n<table style=\"border-collapse: collapse; margin-left: 0; margin-right: 0; text-align: left;\">\n<colgroup>\n<col width=\"624\" \/> <\/colgroup>\n<tbody>\n<tr style=\"height: 0;\">\n<td style=\"background-color: #19171c; padding: 5pt; vertical-align: top;\">\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\"><span style=\"font-size: small; color: #00ff00;\">packer validate httpd.json<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">You should get the output as a success, or as an error indicating the line number.<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">Now run packer build to build your image:-<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"margin-left: 0; text-align: justify;\">\n<table style=\"border-collapse: collapse; margin-left: 0; margin-right: 0; text-align: left;\">\n<colgroup>\n<col width=\"624\" \/> <\/colgroup>\n<tbody>\n<tr style=\"height: 30pt;\">\n<td style=\"background-color: #19171c; padding: 5pt; vertical-align: top;\">\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\"><span style=\"font-size: small; color: #00ff00;\"> packer build httpd.json<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">After a successful build, you will get AMI id as output and success message.<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"margin-left: 0; text-align: justify;\">\n<table style=\"border-collapse: collapse; margin-left: 0; margin-right: 0; text-align: left;\">\n<colgroup>\n<col width=\"624\" \/> <\/colgroup>\n<tbody>\n<tr style=\"height: 0;\">\n<td style=\"background-color: #19171c; padding: 5pt; vertical-align: top;\">\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0;\"><span style=\"font-size: small;\"><span style=\"font-size: small;\"><span style=\"color: #00ff00;\">==&gt; amazon-ebs: Prevalidating AMI Name: PACKER-DEMO-httpd<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0amazon-ebs: Found Image ID: ami-0a574895390037a62<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Creating temporary keypair: packer_5cd559df-84ce-ff8a-fa93-0c4477d988e4<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Creating temporary security group for this instance: packer_5cd559e2-ea81-be15-b94a-c28493c0d3ff<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Authorizing access to port 22 from [0.0.0.0\/0] in the temporary security groups&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Launching a source AWS instance&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Adding tags to source instance<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0amazon-ebs: Adding tag: &#8220;Name&#8221;: &#8220;Packer Builder&#8221;<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0amazon-ebs: Instance ID: i-06ed051a3435865c4<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Waiting for instance (i-06ed051a3435865c4) to become ready&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Using ssh communicator to connect: *.*.*.*<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Waiting for SSH to become available&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Connected to SSH!<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Stopping the source instance&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0amazon-ebs: Stopping instance<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Waiting for the instance to stop&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Creating AMI PACKER-DEMO-httpd from instance i-06ed051a3435865c4<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0amazon-ebs: AMI: ami-0ce41081a3b649374<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Waiting for AMI to become ready&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Adding tags to AMI (ami&#8212;&#8212;)&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Tagging snapshot: snap-0ee3ce80ec289ed24<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Creating AMI tags<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0amazon-ebs: Adding tag: &#8220;Name&#8221;: &#8220;PACKER-DEMO-httpd&#8221;<\/span><br \/>\n<span style=\"color: #00ff00;\">\u00a0\u00a0\u00a0amazon-ebs: Adding tag: &#8220;Env&#8221;: &#8220;DEMO&#8221;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Creating snapshot tags<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Terminating the source AWS instance&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Cleaning up any extra volumes&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: No volumes to clean up, skipping<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Deleting temporary security group&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">==&gt; amazon-ebs: Deleting temporary keypair&#8230;<\/span><br \/>\n<span style=\"color: #00ff00;\">Build &#8216;amazon-ebs&#8217; finished.<\/span><\/span><\/span><span style=\"color: #00ff00;\">==&gt; Builds finished. The artifacts of successful builds are:<\/span><br \/>\n<span style=\"color: #00ff00;\">&#8211;&gt; amazon-ebs: AMIs were created:<\/span><br \/>\n<span style=\"color: #00ff00;\">ap-south-1: ami&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/span><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">Few things to keep in mind:-<\/span><\/div>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/qoLLMwH_Zp1rZzt1bC06xnOTXJ8y8tRuZZBrk3LEhKgQeFmM1RAxZ4np12hfGfGRgXrJ8b3yBrIeZ6gkDqtJut9D7mZRKkMDVlmKbXgDUxUbBDwx-fwdQKAAPC0UxIZYl7bllqva41WkojnNsw\" width=\"400\" height=\"232\" \/><\/span><\/div>\n<div style=\"text-align: justify;\">\n<ul>\n<li><span style=\"font-size: small;\">Packer does not create the image of any running instance, instead, it spins a temporary instance and create the image, post image creation it destroys all the resources which were created by a packer in order to create images.<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">Though packer gives us ease of taking machine AMI\u2019s programmatically, purging of an older image should also be kept in mind because AMIs gets stored over s3 and it might add up to your cost.<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">Though a rollback becomes a lot easier in immutable infra. It can become a pain in the neck if you frequently make changes in production.<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">We cannot expect it to solve all our problems, its only job is to create an image. You will have to decide when to create an image and what post action needs to be taken or deployed after image creation.<\/span><span style=\"font-size: small;\"><br \/>\n<\/span><\/li>\n<\/ul>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">I hope the above setup will help you in getting started with it. Later we will discuss how we can use it along with Ansible and Terraform to achieve immutable Infra. <\/span><\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">I appreciate any suggestions and comments or any questions\/doubts faced while implementing it.<\/span><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this blogpost, we will see how to get started with packer. We will cover installation, writing a template for creating AWS AMI. To get the basic understanding of how packer works, You can refer to our previous blog &#8220;Intro To Packer&#8221;. Installation\u00a0 Official method to download packer as precompiled binary, packer does not provide &hellip; <a href=\"https:\/\/opstree.com\/blog\/2019\/05\/21\/lets-get-started-with-packer\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Lets Get Started With Packer&#8221;<\/span><\/a><\/p>\n","protected":false},"author":168517798,"featured_media":29900,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[28070474,60486],"tags":[305336933,768739292,41395],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2025\/11\/DevSecOps-1.jpg","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfDBOm-s","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/28"}],"collection":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/users\/168517798"}],"replies":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":5,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":30023,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions\/30023"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media\/29900"}],"wp:attachment":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}