Day 29 – Introduction to Packer – Part 1
Welcome to Day 29 of 101 Days of DevOps. The topic for today is Introduction to Packer — Part 1.
What is Packer?
Packer is easy to use and automates the creation of any machine image.
- It integrates natively with a bunch of configuration management systems, e.g., Ansible, Puppet.
- Packer is cross-platform(Linux/Window)
- Packer uses a JSON template file and lets you define immutable infrastructure.
- It’s written in the GO language.
Installing Packer on Ubuntu
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install packer
- Some Packer Options
packer Usage: packer [--version] [--help] <command> [<args>]
Available commands are: build build image(s) from template console creates a console for testing variable interpolation fix fixes templates from old versions of packer fmt Rewrites HCL2 config files to canonical format hcl2_upgrade transform a JSON template into an HCL2 configuration init Install missing plugins or upgrade plugins inspect see components of a template validate check that a template is valid version Prints the Packer version
Packer Template
- Divided into three parts, each of them is a json array, so you can have as many as you want in each section.
Builders
- Use to generate an image, and it’s provider-specific. E.g., if you create an image for AWS, your builder will tell the packer which AMI to start with and what region to create that AMI.
"builders": [{ "type": "amazon-ebs", "access_key": "{{user `aws_access_key`}}", "secret_key": "{{user `aws_secret_key`}}", "region": "us-east-1", "instance_type": "t2.micro", "ssh_username": "ubuntu", "ami_name": "packer-example {{timestamp}}" }]
Provisioners
- It let you customize your images.
- These can be scripts(bash or PowerShell)or your existing configuration management system(e.g., chef, puppet, salt stack, and Ansible) or files where you can upload a file to the running instance for capturing things, e.g., config files, binaries, etc.
"provisioners": [ { "type": "shell", "script": "./example.sh" } ]
Post-Processors
- Let’s integrate with other services like Docker. E.g., it will let you upload an image to dockerhub.
{ "post-processors": [ [ "compress", { "type": "upload", "endpoint": "http://example.com" } ] ] }
If you like to dig deeper into the AWS concept, please feel free to check my book.
Looking forward to you guys joining this journey and spend a minimum of an hour every day for the next 101 days on DevOps work and post your progress using any of the below mediums.
- Website: https://101daysofdevops.com/
- Linkedin: https://www.linkedin.com/in/prashant-lakhera-696119b/
- Twitter: @100daysofdevops OR @lakhera2015
- Facebook: https://www.facebook.com/groups/795382630808645/
- Medium: https://medium.com/@devopslearning
- GitHub: https://github.com/100daysofdevops/100daysofdevops
- YouTube Channel: https://www.youtube.com/user/laprashant/videos
- Slack: https://join.slack.com/t/100daysofdevops/shared_invite/zt-au03logz-YfDUp_FJF4rAUeDEbgWmsg
- Reddit: r/101DaysofDevops
- Meetup: https://www.meetup.com/100daysofdevops/