├── .gitignore ├── scripts ├── cleanup.sh ├── virtualbox.sh ├── puppet.sh ├── vagrant.sh └── base.sh ├── vars.json.template ├── Vagrantfile ├── variables-centos-6.9.json ├── variables-centos-7.3.json ├── http └── vagrant.ks ├── README.md └── vagrant-centos.json /.gitignore: -------------------------------------------------------------------------------- 1 | vars.json 2 | packer_cache 3 | *.box 4 | .vagrant 5 | Vagrantfile 6 | VBoxGuestAdditions.iso 7 | -------------------------------------------------------------------------------- /scripts/cleanup.sh: -------------------------------------------------------------------------------- 1 | dd if=/dev/zero of=/EMPTY bs=1M 2 | rm -f /EMPTY 3 | 4 | rm -rf VBoxGuestAdditions.iso 5 | 6 | sync 7 | -------------------------------------------------------------------------------- /scripts/virtualbox.sh: -------------------------------------------------------------------------------- 1 | mount -o loop /home/vagrant/VBoxGuestAdditions.iso /mnt 2 | sh /mnt/VBoxLinuxAdditions.run 3 | umount /mnt 4 | rm -rf /home/vagrant/VBoxGuestAdditions.iso 5 | -------------------------------------------------------------------------------- /vars.json.template: -------------------------------------------------------------------------------- 1 | { 2 | "iso_url": "", 3 | "iso_checksum": "", 4 | "iso_checksum_type": "", 5 | "guest_additions_path": "", 6 | "redhat_release": "", 7 | "disk_size":"" 8 | } 9 | -------------------------------------------------------------------------------- /scripts/puppet.sh: -------------------------------------------------------------------------------- 1 | RELEASE=`rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)` 2 | rpm -Uvh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-${RELEASE}.noarch.rpm 3 | yum install -y puppet-agent 4 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | 2 | Vagrant.configure("2") do |config| 3 | config.ssh.insert_key = false 4 | config.vm.box = "vagrant-centos-6.9" 5 | config.vm.provider "virtualbox" do |vb| 6 | vb.customize ["modifyvm", :id, "--memory", 1024] 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /scripts/vagrant.sh: -------------------------------------------------------------------------------- 1 | mkdir -pm 700 /home/vagrant/.ssh 2 | curl -L https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -o /home/vagrant/.ssh/authorized_keys 3 | chmod 0600 /home/vagrant/.ssh/authorized_keys 4 | chown -R vagrant:vagrant /home/vagrant/.ssh 5 | -------------------------------------------------------------------------------- /scripts/base.sh: -------------------------------------------------------------------------------- 1 | RELEASE=`rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)` 2 | rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-${RELEASE}.noarch.rpm 3 | yum -y install gcc make gcc-c++ kernel-devel-`uname -r` perl wget bzip2 4 | yum -y update 5 | reboot 6 | sleep 60 7 | -------------------------------------------------------------------------------- /variables-centos-6.9.json: -------------------------------------------------------------------------------- 1 | { 2 | "iso_url": "http://centos.po.opole.pl/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso", 3 | "iso_checksum": "422af57b493b8af49d485885a730c5a1d955f803fac85aa51311c393168b9080", 4 | "iso_checksum_type": "sha256", 5 | "guest_additions_path": "VBoxGuestAdditions.iso", 6 | "redhat_release": "6.9", 7 | "disk_size": "10000" 8 | } 9 | -------------------------------------------------------------------------------- /variables-centos-7.3.json: -------------------------------------------------------------------------------- 1 | { 2 | "iso_url": "http://ftp.ps.pl/pub/Linux/CentOS/7/isos/x86_64/CentOS-7-x86_64-Minimal-1611.iso", 3 | "iso_checksum": "27bd866242ee058b7a5754e83d8ee8403e216b93d130d800852a96f41c34d86a", 4 | "iso_checksum_type": "sha256", 5 | "guest_additions_path": "VBoxGuestAdditions.iso", 6 | "redhat_release": "7.3", 7 | "disk_size": "15000" 8 | } 9 | -------------------------------------------------------------------------------- /http/vagrant.ks: -------------------------------------------------------------------------------- 1 | install 2 | cdrom 3 | 4 | lang en_GB.UTF-8 5 | keyboard us 6 | timezone Europe/London 7 | 8 | network --onboot yes --bootproto=dhcp --device=eth0 --activate --noipv6 9 | 10 | rootpw vagrant 11 | authconfig --enableshadow --passalgo=sha512 12 | user --name=vagrant --groups=vagrant --password=vagrant 13 | 14 | firewall --disabled 15 | selinux --disabled 16 | firstboot --disabled 17 | 18 | bootloader --location=mbr 19 | text 20 | skipx 21 | 22 | logging --level=info 23 | zerombr 24 | clearpart --all --initlabel 25 | autopart 26 | 27 | reboot 28 | 29 | 30 | %packages --nobase 31 | @Core 32 | openssh-clients 33 | openssh-server 34 | %end 35 | 36 | %post --log=/root/post_install.log 37 | 38 | # Add vagrant to sudoers 39 | /bin/echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant 40 | /bin/chmod 0440 /etc/sudoers.d/vagrant 41 | /bin/sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers 42 | 43 | %end 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Packer Centos template 2 | ============== 3 | 4 | Packer template to make VirtualBox images. 5 | 6 | Notes 7 | ----- 8 | CentOS 64-bit VM, 10G disk, EPEL repo, Puppet 4, no SELinux, no firewall, 9 | 10 | Packer version: 0.8.6 11 | 12 | Usage 13 | ===== 14 | 15 | Installing Packer 16 | ----------------- 17 | 18 | Download the latest packer from http://www.packer.io/downloads.html 19 | 20 | Prepare var file 21 | ---------------------- 22 | 23 | `cp vars.json.template vars-example.json` 24 | 25 | Example var file for CentOS 7.x: 26 | 27 | ```json 28 | { 29 | "iso_url": "http://ftp.ps.pl/pub/Linux/CentOS/7/isos/x86_64/CentOS-7-x86_64-Minimal-1611.iso", 30 | "iso_checksum": "27bd866242ee058b7a5754e83d8ee8403e216b93d130d800852a96f41c34d86a", 31 | "iso_checksum_type": "sha256", 32 | "guest_additions_path": "VBoxGuestAdditions.iso", 33 | "redhat_release": "7.3", 34 | "disk_size": "15000" 35 | } 36 | 37 | ``` 38 | Example var file for CentOS 6.x: 39 | 40 | ```json 41 | { 42 | "iso_url": "http://centos.po.opole.pl/6/isos/x86_64/CentOS-6.9-x86_64-minimal.iso", 43 | "iso_checksum": "422af57b493b8af49d485885a730c5a1d955f803fac85aa51311c393168b9080", 44 | "iso_checksum_type": "sha256", 45 | "guest_additions_path": "VBoxGuestAdditions.iso", 46 | "redhat_release": "6.9", 47 | "disk_size": "10000" 48 | } 49 | ``` 50 | 51 | Running Packer 52 | -------------- 53 | 54 | `$ packer build -var-file=vars-example.json vagrant-centos.json` 55 | -------------------------------------------------------------------------------- /vagrant-centos.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": 3 | { 4 | "iso_url": "", 5 | "iso_checksum": "", 6 | "iso_checksum_type": "", 7 | "guest_additions_path": "", 8 | "redhat_release": "", 9 | "disk_size":"" 10 | }, 11 | 12 | "builders": [ 13 | { 14 | "type": "virtualbox-iso", 15 | "vm_name": "centos-vm", 16 | "boot_wait": "10s", 17 | "disk_size": "{{user `disk_size`}}", 18 | "guest_os_type": "RedHat_64", 19 | "http_directory": "http", 20 | 21 | "iso_url": "{{user `iso_url`}}", 22 | "iso_checksum": "{{user `iso_checksum`}}", 23 | "iso_checksum_type": "{{user `iso_checksum_type`}}", 24 | "guest_additions_path": "{{user `guest_additions_path`}}", 25 | 26 | "boot_command": [ 27 | " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/vagrant.ks" 28 | ], 29 | "shutdown_command": "echo 'vagrant'|sudo -S /sbin/halt -h -p", 30 | "shutdown_timeout" : "10s", 31 | "ssh_username": "vagrant", 32 | "ssh_password": "vagrant", 33 | "ssh_port": 22, 34 | "hard_drive_interface": "sata", 35 | "ssh_wait_timeout": "60m", 36 | "output_directory": "builds", 37 | "vboxmanage": [ 38 | [ "modifyvm", "{{.Name}}", "--memory", "640" ], 39 | [ "modifyvm", "{{.Name}}", "--cpus", "2" ] 40 | ], 41 | "virtualbox_version_file": ".vbox_version" 42 | } 43 | ], 44 | 45 | "post-processors": [ 46 | { 47 | "output": "vagrant-centos-{{user `redhat_release`}}.box", 48 | "compression_level": "6", 49 | "type": "vagrant" 50 | } 51 | ], 52 | 53 | "provisioners": [ 54 | { 55 | "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'", 56 | "type": "shell", 57 | "override": { 58 | "virtualbox-iso": { 59 | "scripts": [ 60 | "scripts/base.sh", 61 | "scripts/vagrant.sh", 62 | "scripts/virtualbox.sh", 63 | "scripts/cleanup.sh", 64 | "scripts/puppet.sh" 65 | ] 66 | } 67 | } 68 | } 69 | ] 70 | } 71 | --------------------------------------------------------------------------------