{"id":34,"date":"2019-05-21T04:48:00","date_gmt":"2019-05-21T04:48:00","guid":{"rendered":"https:\/\/opstree.com\/blog\/\/2019\/05\/21\/intro-to-packer\/"},"modified":"2025-11-27T16:58:45","modified_gmt":"2025-11-27T11:28:45","slug":"intro-to-packer","status":"publish","type":"post","link":"https:\/\/opstree.com\/blog\/2019\/05\/21\/intro-to-packer\/","title":{"rendered":"Intro to Packer"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p id=\"docs-internal-guid-f8107164-7fff-9776-19ae-ece260fe7c1b\" dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">Packer is an opensource tool developed by HashiCorp to create machine images for multiple cloud platforms like AWS, GCP, Azure or even VMWare. As the name suggests it packs all your software, packages, configurations while baking your machine images. Perhaps Packer is the only tool right now in the market which solely focuses on creating machine images and giving us the ability to automate the machine image creation process.<\/span><\/p>\n<p dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">In this blog post, we will learn What Packer does and how it does things. Sounds Interesting!!!! <\/span><\/p>\n<div style=\"text-align: justify;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\">\n<div style=\"text-align: center;\"><span style=\"font-size: small;\">What is Packer and Machine Images<\/span><\/div>\n<\/div>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\">\n<div style=\"text-align: center;\"><span style=\"font-size: small;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/ydBMAYZ2QlOhYPSJ0bJv8iDara-rUPyQCdeYY7g2d4QCWoDel8AK6EnkqcMuqalE_knHaxAGxoO_u8BwP4T5yi-H7Vu3AOm5WZJVKbKfu4qm6tzQzM6Elj6_EJVtVZjz4Fz95L_HbtgN-BsjIw\" width=\"400\" height=\"228\" \/><\/span><\/div>\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;\">&#8220;Packer can be used to creating identical machine images for multiple platforms from a single source configuration. Packer is lightweight, runs on every major operating system, and is highly performant, creating machine images for multiple platforms in parallel.&#8221;\u00a0<\/span><br \/>\n<span style=\"font-size: small;\"><a href=\"https:\/\/www.packer.io\/intro\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.packer.io\/intro\/<\/a>\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;\">It does installs and configures the software by using different SCM tools such as Ansible, Chef or Puppet, shell scripts within your Packer-made images. You can either include your scripts in json template itself or you can source it from a 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;\">&#8220;A machine image is a single static unit that contains a pre-configured operating system and installed software which is used to quickly create new running machines. Machine image formats change for each platform. Some examples include <a style=\"text-decoration: none;\" href=\"https:\/\/en.wikipedia.org\/wiki\/Amazon_Machine_Image\" target=\"_blank\" rel=\"noopener\">AMIs<\/a> for EC2, VMDK\/VMX files for VMware, OVF exports for VirtualBox, etc&#8221;<\/span><br \/>\n<span style=\"font-size: small;\"><a href=\"https:\/\/www.packer.io\/intro\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.packer.io\/intro\/<\/a>\u00a0<\/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;\">\n<div style=\"text-align: center;\"><span style=\"font-size: small;\">Why the Heck We Should Consider to Learn Packer!!!!!!!!<img loading=\"lazy\" decoding=\"async\" style=\"border: none;\" src=\"https:\/\/lh5.googleusercontent.com\/RrJaAxVu9zlkWp-OLttzS8flGab_hM3FcwcsL0MVLOWI8KhvBFdSRJbXpGCCZoDCYsKWUsrjV911y4FYx10hwUGjHX8ghuppcCVS-JbA4qXj6QhaRBDTED9F2Xiv2bkP34Vac2sVp6Ap9aR4Rg\" width=\"559\" height=\"277\" \/><\/span><\/div>\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;\">Consider a couple of scenarios mentioned below:-<\/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;\">Scenario1<\/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;\">If you want to have an immutable infrastructure in place. The key guideline behind an immutable infrastructure is that you never modify a running server. If a change is required, you instead completely replace the server with a new instance that contains the update or change.<\/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\" style=\"border: none;\" src=\"https:\/\/docs.google.com\/drawings\/u\/1\/d\/stqVdKcR5fSc7izhJm3bw8A\/image?w=426&amp;h=61&amp;rev=1&amp;ac=1&amp;parent=1_bvJc9l071uqEEVR7zrfZ_2RwfpaGEWZoJIt5XODjcI\" width=\"426\" height=\"61\" \/><\/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;\">The new server instance is created with an origin image that is built upon or a restored image from a previously defined server state. Version control and tag your images for easy rollback and distribution. Image contains all the application code, runtime dependencies, and configuration\u2013in essence, the state needed for the software to run as expected. You will want to minimize the time required to bake all your required stuff into your image which can be achieved if you have proper tag maintained over your previous release images which can be used as an origin-golden image to bake the new image. The entire process of baking and using images become outstandingly easy by using Packer.<\/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;\">Scenario2<\/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;\">If you have autoscaling in place, there must be a requirement to scale up a new serviceable VMs as soon as possible but there are some concerns which spoil your expectations of serviceable VMs in the least time:<\/span><\/div>\n<ul style=\"text-align: justify;\">\n<li><span style=\"font-size: small;\">OS boot<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">OS configuration<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">SCM with Ansible or Chef<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">Setting up your application<\/span><\/li>\n<\/ul>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">With having a pre-baked image in place, your time to scale up your VMs will drastically decrease.<\/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;\">\n<div style=\"text-align: center;\"><span style=\"font-size: small;\">So How Does Packer Works!!!!!!!!<\/span><\/div>\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;\">\n<div style=\"text-align: center;\"><span style=\"font-size: small;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/KTCftD7v0HvhWXOQ6K9HiLsTdIahhn07zLlDXPqgLkbSlVnRsW6mz4ZwWVs3oTkB0w2WeWDuajroPJyY7Uwic14V0IilHoDxbHzCCy13KD4tO8fiI9VGfGY9id-EnNZ09Xr8iibXBONnN2wQxA\" width=\"400\" height=\"274\" \/><\/span><\/div>\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;\">Packer uses the JSON file as a template, it takes template as in input rolls up a temporary VMs based on the details provided, does the required configuration and stops it. After stopping the VMs it starts creating the image and save it as the name\/tag provided in the template.<\/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;\"> \u00a0<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/docs.google.com\/drawings\/u\/1\/d\/sQR_Pd4tH0igHOwCYCY9MvQ\/image?w=505&amp;h=94&amp;rev=1&amp;ac=1&amp;parent=1_bvJc9l071uqEEVR7zrfZ_2RwfpaGEWZoJIt5XODjcI\" width=\"505\" height=\"94\" \/><\/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>json file packer engine EC2 AMI<\/i><\/span><span style=\"font-size: small;\"><br \/>\n<\/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;\">\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;\"> \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;\">Basic Concepts of Packer<\/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;\">There are two things which you will need to know to get started with packer:<\/span><\/div>\n<div style=\"text-align: justify;\">\n<ul>\n<li><span style=\"font-size: small;\">Templates<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">Commands<\/span><\/li>\n<\/ul>\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;\">Templates<\/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;\">There are four sections in the Packer template:\u00a0<\/span><\/div>\n<ul style=\"text-align: justify;\">\n<li><span style=\"font-size: small;\">Variables(optional)-is an object of one or more key\/value strings that define user variables contained in the template. If it is not specified, then no variables are defined<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">Builders(required)- is an array of one or more objects that defines the builders that will be used to create machine images for this template, and configures each of those builders.<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">Provisioners(optional)- is an array of one or more objects that defines the provisioners that will be used to install and configure the software for the machines created by each of the builders<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">post-processors(optional)- \u00a0is an array of one or more objects that defines the various post-processing steps to take with the built images. If not specified, then no post-processing will be done<\/span><\/li>\n<\/ul>\n<div dir=\"ltr\" style=\"line-height: 1.38; margin-bottom: 0; margin-top: 0; text-align: justify;\"><span style=\"font-size: small;\">Sub-Commands<\/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;\">Likewise, Unix packer also takes subcommand and options. There are three sub-commands:<\/span><\/div>\n<ul style=\"text-align: justify;\">\n<li><span style=\"font-size: small;\">build-The packer build command takes a template and runs all the builds within it in order to generate a set of artefacts. The various builds specified within a template are executed in parallel unless otherwise specified. And the artefacts that are created will be outputted at the end of the build.\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">validate- The packer validate command is used to validate the syntax and configuration of a <a style=\"text-decoration: none;\" href=\"https:\/\/www.packer.io\/docs\/templates\/index.html\" target=\"_blank\" rel=\"noopener\">template<\/a>. The command will return a zero exit status on success, and a non-zero exit status on failure. Additionally, if a template doesn&#8217;t validate, any error messages will be outputted.<\/span><span style=\"font-size: small;\">\u00a0<\/span><\/li>\n<li><span style=\"font-size: small;\">inspect -The packer inspect takes a template and outputs the various components a template defines. This can help you quickly learn about a template without having to dive into the JSON itself. The command will tell you things like what variables a template accepts, the builders it defines, the provisioners it defines and the order they&#8217;ll run, and more.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: small;\">Hope this blog helps you understand the basics of Packer. Having covered all the basics understanding, we can now &#8220;Get Started With Packer&#8221;.<\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Packer is an opensource tool developed by HashiCorp to create machine images for multiple cloud platforms like AWS, GCP, Azure or even VMWare. As the name suggests it packs all your software, packages, configurations while baking your machine images. Perhaps Packer is the only tool right now in the market which solely focuses on creating &hellip; <a href=\"https:\/\/opstree.com\/blog\/2019\/05\/21\/intro-to-packer\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Intro to 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-y","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/34"}],"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=34"}],"version-history":[{"count":4,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"predecessor-version":[{"id":30081,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/34\/revisions\/30081"}],"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=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}