From e42bc5c08da0778e126a2185aff64f199d88c216 Mon Sep 17 00:00:00 2001 From: Jim Van Fleet Date: Thu, 7 Jul 2016 09:28:30 -0400 Subject: [PATCH] Initial packer setup --- .gitignore | 5 +++ README.md | 49 +++++++++++++++++++++++++-- ansible/main.yml | 8 +++++ centos7.json | 58 ++++++++++++++++++++++++++++++++ http/ks.cfg | 83 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/ansible.sh | 7 ++++ scripts/cleanup.sh | 11 ++++++ 7 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 ansible/main.yml create mode 100644 centos7.json create mode 100644 http/ks.cfg create mode 100644 scripts/ansible.sh create mode 100644 scripts/cleanup.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b60c030 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +packer_cache/* +*.box +iso/* +output-virtualbox-iso/* +builds/* diff --git a/README.md b/README.md index a7b3880..0198684 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,47 @@ -# packer-centos-7 -Packaging instructions for VM appliances +# Packer Image Builder for CentOS + +## Introduction + +This packer templates create vmware image of CentOS 7 with `.vmx` file type. + +The OS versions are: + + - Centos 7 + +For all operating systems we generate images for + + - VmWare (user: packer/changeme1234) + +This template only is tested against 64 bit systems. With the following sizing requirements: +``` + "vmx_data": { + "cpuid.coresPerSocket": "1", + "memsize": "512", + "numvcpus": "2" + } +``` + +``` + "disk_size": 81920 +``` + +## Requirements + +The templates are only tested with [packer](http://www.packer.io/downloads.html) 0.10.1 and later. + +## Run conversion process + + # Build CentOS VMWare image + PACKER_LOG=1 packer build centos7.json + +## Issues during build time + +If you experience issues with packer, please use `PACKER_LOG=1 packer ... ` to find the errors. + +## Author + + - Author:: Mason Packard () + +# License + +TBD diff --git a/ansible/main.yml b/ansible/main.yml new file mode 100644 index 0000000..71290a2 --- /dev/null +++ b/ansible/main.yml @@ -0,0 +1,8 @@ +--- +- hosts: all + become: yes + gather_facts: yes + + tasks: + - name: "Run the Playbook" + shell: echo "<-------~ Playbook Start ~---------->" diff --git a/centos7.json b/centos7.json new file mode 100644 index 0000000..9d1b13c --- /dev/null +++ b/centos7.json @@ -0,0 +1,58 @@ +{ + "provisioners": [ + { + "type": "shell", + "execute_command": "echo 'packer' | {{.Vars}} sudo -S -E bash '{{.Path}}'", + "script": "scripts/ansible.sh" + }, + { + "type": "ansible-local", + "playbook_file": "ansible/main.yml" + }, + { + "type": "shell", + "execute_command": "echo 'packer' | {{.Vars}} sudo -S -E bash '{{.Path}}'", + "script": "scripts/cleanup.sh" + } + ], + "builders": [ + { + "type": "vmware-iso", + "name": "centos-7-vmx", + "boot_command": [ + " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" + ], + "boot_wait": "10s", + "disk_size": 81920, + "guest_os_type": "centos-64", + "headless": true, + "http_directory": "http", + "iso_urls": [ + "CentOS-7-x86_64-Minimal-1511.iso", + "http://mirror.vcu.edu/pub/gnu+linux/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1511.iso" + ], + "iso_checksum_type": "md5", + "iso_checksum": "88c0437f0a14c6e2c94426df9d43cd67", + "output_directory": "img-centos-7-vmware", + "ssh_username": "packer", + "ssh_password": "changeme1234", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "echo 'packer'|sudo -S /sbin/halt -h -p", + "tools_upload_flavor": "linux", + "vm_name": "packer-centos-7-x86_64", + "vmdk_name": "packer-centos-7-x86_64-disk0", + "vmx_data": { + "cpuid.coresPerSocket": "1", + "memsize": "512", + "numvcpus": "2" + } + } + ], + "post-processors": [ + { + "output": "builds/packer_centos7_{{.BuilderType}}.tar", + "type": "compress" + } + ] +} diff --git a/http/ks.cfg b/http/ks.cfg new file mode 100644 index 0000000..90b7fe4 --- /dev/null +++ b/http/ks.cfg @@ -0,0 +1,83 @@ +install +cdrom +lang en_US.UTF-8 +keyboard us +unsupported_hardware +network --bootproto=dhcp +rootpw changeme1234 +firewall --disabled +selinux --permissive +timezone UTC +unsupported_hardware +bootloader --location=mbr +text +skipx +zerombr +clearpart --all --initlabel +autopart +auth --enableshadow --passalgo=sha512 --kickstart +firstboot --disabled +eula --agreed +services --enabled=NetworkManager,sshd +reboot +user --name=packer --plaintext --password changeme1234 --groups=tier_group,wheel + +%packages --ignoremissing --excludedocs +@Base +@Core +@Development Tools +openssh-clients +sudo +openssl-devel +readline-devel +zlib-devel +kernel-headers +kernel-devel +net-tools +vim +wget +curl +rsync + +# unnecessary firmware +-aic94xx-firmware +-atmel-firmware +-b43-openfwwf +-bfa-firmware +-ipw2100-firmware +-ipw2200-firmware +-ivtv-firmware +-iwl100-firmware +-iwl1000-firmware +-iwl3945-firmware +-iwl4965-firmware +-iwl5000-firmware +-iwl5150-firmware +-iwl6000-firmware +-iwl6000g2a-firmware +-iwl6050-firmware +-libertas-usb8388-firmware +-ql2100-firmware +-ql2200-firmware +-ql23xx-firmware +-ql2400-firmware +-ql2500-firmware +-rt61pci-firmware +-rt73usb-firmware +-xorg-x11-drv-ati-firmware +-zd1211-firmware +%end + +%post +yum update -y + +# update root certs +wget -O/etc/pki/tls/certs/ca-bundle.crt http://curl.haxx.se/ca/cacert.pem + +# sudo +yum install -y sudo +echo "packer ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/packer +sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers + +yum clean all +%end diff --git a/scripts/ansible.sh b/scripts/ansible.sh new file mode 100644 index 0000000..9c6619e --- /dev/null +++ b/scripts/ansible.sh @@ -0,0 +1,7 @@ +#!/bin/bash -eux + +# Install EPEL repository. +yum -y install epel-release + +# Install Ansible. +yum -y install ansible diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh new file mode 100644 index 0000000..0eff8cb --- /dev/null +++ b/scripts/cleanup.sh @@ -0,0 +1,11 @@ +#!/bin/bash -eux + +# Remove Ansible and its dependencies. +yum -y remove ansible + +# Zero out the rest of the free space using dd, then delete the written file. +dd if=/dev/zero of=/EMPTY bs=1M +rm -f /EMPTY + +# Add `sync` so Packer doesn't quit too early, before the large file is deleted. +sync