openstack-基于packer自动化build镜像

Packer是一个从单一的模板文件来创建多平台一致性镜像的轻量级开源工具它能够运行在常用的主流操作系统如Windows、Linux和Mac os上能够高效的并行创建多平台例如AWS、Azure和Alicloud/OpenStack镜像它的目的并不是取代Puppet/Chef等配置管理工具,实际上,当制作镜像的时候,Packer可以使用Chef或者Puppet,ansible 等工具来安装镜像所需要的软件。通过Packer自动化的创建各种平台的镜像是非常容易的。

安装packer

#wget https://releases.hashicorp.com/packer/1.7.10/packer_1.7.10_linux_amd64.zip
#unzip packer_1.7.10_linux_amd64.zip
#mv packer /usr/local/bin/
#/usr/local/bin/packer --help

定义paopenstack的主要组件及功能cker模板云计算导论

#touch openstack.json
#vim openstack.json

{
"builders": [{
"type": "openstack",
"identity_endpoint": "http://10.224.130.100:35357/v3",
"tenant_name": "admin",
"domain_name": "default",
"username": "admin",
"password": "password",
"ssh_username": "root",
"region": "bj",
"image_name": "Ubuntu-image-updating-powered-by-Packer",
"instance_name": "Ubuntu-image-updating-powered-by-Packer",
"source_image": "c751e91f-80f7-43a1-afea-58287a8df695",
"availability_zone": "nova",
"flavor": "ecs.large",
"use_blockstorage_volume": true,
"networks": ["9df8061e-abb2-4166-9c16-452f389c3e39"]
}],
"provisioners": [
{
"type": "shell",
"scripts": ["os-init.sh"]
}
],
"post-processors": [{
"strip_path": true,
"output": "packer-template-ubuntu-updating-result.log",
"type": "manifest"
}]
}

#vim os-init.sh

#!/bin/bash
# os-init.sh
yum -y install gcc

build 镜像

packer build openstack.json

感受一下packer的魔力吧~