Packer is a free, open source application from Hashicorp. It can generate a server image based on an existing one, and configure it for your special needs. You can use the generated image when you launch a server instance in the cloud or on your local workstation.
Generate the server image with Packer
- Open a Bash window,
- Navigate to the folder of the Packer JSON script,
- Execute the following command. Get the AWS access key and secret key from the ~/.aws/credentials file on your Macintosh or Linux workstation. On Windows, the file is at C:\Users\YOUR_USER_NAME\.aws\credentials.
packer build -var 'aws_access_key=MY_ACCESS_KEY' -var 'aws_secret_key=MY_SECRET_KEY' ./MY_PACKER_SCRIPT.json
- The command window will display the ID of the generated image, or you can find it by name in the EC2 section of the AWS console under AMIs.
Share the generated server image with other cloud accounts
If you work in multiple cloud accounts you need to share the generated server image with other accounts
- Log into the AWS account you have used to generate the server image,
- On the left side of the EC2 section select AMI and find the new image by name of ID,
- On the Permissions tab click the Edit button,
- Make sure the Private radio button is selected if you don’t want to share the image publicly,
- Enter the account number of the account you want to share the image with,
- Check the Add “create volume” permissions… checkbox,
- Click the Add Permission button,
- When you have added all accounts to share with, click the Save button.
When you use RightScale to launch servers in the cloud, you want to use the same base image to test your Chef cookbooks in Test Kitchen.
Packer by Hashicorp is a utility to create custom server images based on cloud images. You supply the image ID and other configuration parameters to create a new custom image.
To find the AMI ID of the base image of the RightScale Server Template
- Open the RightScale user interface in your browser,
- Select the RightScale account where the server template was created,
- In RightScale Cloud Management select Design / ServerTemplates,
- Select the server template,
- Select Images,
- Select the MultiCloud image,
- Select Clouds,
- Select the image in the region you are working in,
- The Resource UID is the AMI ID of the image.
Most of the DevOps tools are still in beta versions, many times the new version is not compatible with your existing scripts or have an error that stops your scripts working. To be able to keep multiple versions of the applications and easily switch between them, create symbolic links and point to the version you want to execute.
Create version specific locations
Create a folder for your optional applications.
Set you as the owner of the “opt” directory and it’s children
sudo chown -R YOUR_USER_NAME:wheel /opt
Set the security of the folder.
sudo chmod 755 /opt
We will create a directory structure to place each version of the application into its own folder.
Create a symbolic link to point to the application in the appropriate version folder. These are the examples for Packer, Terraform, and Vagrant. Notice, that the Vagrant application is in the “bin” directory, so the symbolic link has to point there.
ln -s /opt/packer/packer_1.0.0/packer packer
ln -s /opt/terraform/terraform_0.9.7/terraform terraform
ln -s /opt/vagrant/vagrant_1.9.1/bin/vagrant vagrant #The vagrant application is in the bin folder
Add the main application folder to the path in the config file of your terminal
- for iTerm2 with zterminal: ~/.zshrc
- for other terminals: ~/.bash_profile
Vagrant has an installer, that places the bin and embedded folders to “/opt/vagrant”. To be able to keep multiple versions of Vagrant execute the following:
mkdir vagrant_MY_VERSION # Create a folder for the new version
sudo chown -R YOUR_USER_NAME:wheel bin # Set the owner, so you can move it
sudo chown -R YOUR_USER_NAME:wheel embedded # Set the owner, so you can move it
mv bin vagrant_MY_VERSION # Move the folder to the version specific location
mv embedded vagrant_MY_VERSION # Move the folder to the version specific location
rm vagrant # Delete the old version of the symbolic link
ln -s /opt/vagrant/vagrant_MY_VERSION/bin/vagrant vagrant # Create the symbolic link
To change the version you want to execute
- Delete the symbolic link,
- Create a new symbolic link pointing to the other version of the application as above.