Packer by HashiCorp
In this article:
Packer by HashiCorp#
You can use Packer 1.5.x to automate the creation of modified images.
Installation and configuration#
Download and unpack the Packer executable file ver. 1.5.x for the required OS and processor architecture. If the official page is unavailable, download the installation package here. To use Packer, allocate a public address and import a public SSH key first.
Template file example#
This example uses Fedora 28 [Cloud Images], shell provisioner, and amazon-ebs builder to create a modified image. In Packer terms, the configuration file with the description of the created image is called template and is a JSON file.
template_fedora.json
{
"builders": [{
"type": "amazon-ebs",
"access_key": "<my_ec2_access_key>",
"secret_key": "<my_ec2_secret_key>",
"skip_region_validation": true,
"region": "ngn",
"availability_zone": "ru-msk-vol51",
"subnet_id": "<subnet_id>",
"ssh_keypair_name": "cloud_key",
"ssh_private_key_file": "/home/test_user/.ssh/cloud_key",
"custom_endpoint_ec2": "https://ec2.cloud.ngn.com.tr",
"source_ami": "cmi-3214AD17",
"instance_type": "m2.small",
"ssh_username": "ec2-user",
"ami_name": "fedora_modified_cmi",
}],
"provisioners" : [{
"script": "./setup.sh",
"type": "shell"
}]
}
setup.sh
#!/bin/sh
echo "have fun!¡" >> ~/.bash_profile
Currently, NGN Cloud Platform supports only amazon-ebs builder. You can read more information about creation of templates in the documentation. In the template_fedora.json
example, the following parameters are used:
access_key and secret_key — API access keys, getting of which is described in the documentation;
skip_region_validation — to skip the region validation step put the
true
value here;region — supported region (
ngn
only);availability_zone — one of the available availability zones for an instance launch;
subnet_id — id of the subnet, where the instance will be launched;
ssh_keypair_name – name of the imported SSH key;
ssh_private_key_file – path to the private SSH key;
custom_endpoint_ec2 — NGN Cloud EC2 API address;
source_ami — ID of the base image;
instance_type — type of instance to launch when the image is created;
ssh_username — name of the user used to establish an SSH connection;
ami_name — name of new image;