If you already have a Linux workstation or access to a Linux server with hardware virtualization support, you can use that.
Or, if you have access to any OpenStack environment and have it configured to passthrough the hardware virtualization flags to the OpenStack Instance, you can create an OpenStack Instance from any modern Ubuntu or CentOS cloud image.
The following instructions will focus on using a CentOS 7 based workstation/server/instance as the build host and will result in creating two CentOS 7 OpenStack compatible images: an XFS image and a ext4 image.
Install QEMU:
yum install qemu-kvm unzip git
Packer needs qemu-kvm available in the BASH path. For some reason it isn't added. Add it:
echo 'export PATH=$PATH:/usr/libexec' > /etc/profile.d/libexec-path.sh
Also, add /usr/local/bin to your BASH path:
echo 'export PATH=$PATH:/usr/local/bin' > /etc/profile.d/usr-local-bin-path.sh
You might need to log out and log back into the root user for the BASH path changes to take affect.
Download the latest version of Packer.
At the time of writing, Packer 0.10.1 is the latest. Download it using curl
:
curl -O https://releases.hashicorp.com/packer/0.10.1/packer_0.10.1_linux_amd64.zip
Unzip packer:
unzip packer_0.10.1_linux_amd64.zip
There's already a program named packer in the BASH path. Rename the packer you just downloaded to packerio:
mv /root/packer /root/packerio
Move the newly renamed packerio binary to /usr/local/bin:
mv /root/packerio /usr/local/bin
Download the packer-templates-rax repository:
git clone https://github.com/rsoprivatecloud/packer-templates-rax.git
Change into the appropriate directory:
cd packer-templates-rax
Finally, run packer
:
packerio build template-centos-7-x86_64-1511-rax-openstack.json
After about 10 minutes, the images will be created.
The resulting image is larger than it needs to be. It can be compressed and the current size reduced by half.
Change into the appropriate directory:
cd output-centos-7-x86_64-1511-rax-xfs
Compress the image:
qemu-img convert -c centos-7-x86_64-1511-rax-xfs -O qcow2 centos-7-x86_64-1511-rax-xfs.qcow2
Change into the appropriate directory:
cd output-centos-7-x86_64-1511-rax-ext4
Compress the image:
qemu-img convert -c centos-7-x86_64-1511-rax-ext4 -O qcow2 centos-7-x86_64-1511-rax-ext4.qcow2
If you don't already have the glance
command available, you will need to install it.
Install the necessary packages:
yum install gcc python-pip python-devel
Install pip:
easy_install pip
Install the necessary Python depedences:
pip install netifaces
Instsall python-glanceclient:
pip install python-glanceclient
Download an openrc file from your OpenStack environment associated with the OpenStack Project you want the Glance Image to be available in.
You could also make the Glance Image Public within OpenStack so every OpenStack Project can see it.
Source the openrc file:
source /root/openrc
Upload the XFS image to Glance with the following command:
glance image-create --name centos-7-x86_64-1511-rax-xfs --disk-format=qcow2 --container-format=bare --file centos-7-x86_64-1511-rax-xfs.qcow2
Upload the ext4 image to Glance with the following command:
glance image-create --name centos-7-x86_64-1511-rax-ext4 --disk-format=qcow2 --container-format=bare --file centos-7-x86_64-1511-rax-ext4.qcow2
You should now be able to create OpenStack Instances from the new Glance Images.
Packer Image Builder for RHEL Family (RedHat, CentOS, Oracle Linux)