Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jmassara committed Jul 31, 2014
0 parents commit 0cc709d
Show file tree
Hide file tree
Showing 12 changed files with 379 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
packer_cache/
output-*
*.box
*.tar.gz
iso
crash.log
tmp
.vagrant/
*.swp
box/
.DS_Store
26 changes: 26 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2014, James Massara. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Packer templates for Red Hat Enterprise 7 x86_64

## Overview

This repository contains templates for [RHEL7](https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/index.html)
x86_64 that creates [Vagrant](http://vagrantup.com) boxes using [Packer](http://packer.io).

## Prerequisites

To build all the boxes, you will need Packer and both VirtualBox and VMware
Fusion installed. You will also need the RHEL7 64-bit ISO from Red Hat and, if
using VirtualBox, the guest additions ISO matching the version of VirtualBox you
are using (see [here](http://download.virtualbox.org/virtualbox)). VMWare Fusion
comes packaged with their tools.

Once you've obtained the ISOs, copy all of them into the same directory
(e.g. /usr/local/isos).

## Creating the boxes

* Export `ISO_LOCATION` to the directory where the ISOs reside
* Run packer with either the `rhel-7.0-vbox.json` or `rhel-7.0-vmware.json` template
* Add the box to Vagrant
* Build VMs

### Example

```
$ export ISO_LOCATION=file:///usr/local/isos
$ packer build rhel-7.0-vbox.json
$ packer build rhel-7.0-vmware.json
$ vagrant box add rhel-7.0-vbox ./rhel-7.0-vbox.box
$ vagrant box add rhel-7.0-vmware ./rhel-7.0-vmware.box
```
41 changes: 41 additions & 0 deletions http/vbox-ks.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
install
cdrom
lang en_US.UTF-8
keyboard us
network --bootproto=dhcp --hostname=baseline
rootpw --plaintext vagrant
firewall --disable
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc America/Los_Angeles
bootloader --location=mbr
text
skipx
zerombr
clearpart --all
autopart
firstboot --disabled
# --gid option is currently bugged in RHEL7 so this is handled in %post below
# user --name=vagrant --password=vagrant --groups=wheel --uid=9999 --gid=9999
reboot

%packages --nobase
@core
bzip2
gcc
gcc-c++
kernel-devel
make
net-tools
ntp
sudo
-biosdevname
%end

%post
groupadd -g 9999 vagrant
useradd -u 9999 -g vagrant -G wheel vagrant
echo "vagrant" | passwd --stdin vagrant
sed -E -i '/Defaults[[:space:]]+requiretty/ s/^/#/' /etc/sudoers
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
%end
41 changes: 41 additions & 0 deletions http/vmware-ks.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
install
cdrom
lang en_US.UTF-8
keyboard us
network --bootproto=dhcp --hostname=baseline
rootpw --plaintext vagrant
firewall --disable
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc America/Los_Angeles
bootloader --location=mbr
text
skipx
zerombr
clearpart --all
autopart
firstboot --disabled
# --gid option is currently bugged in RHEL7 so this is handled in %post below
# user --name=vagrant --password=vagrant --groups=wheel --uid=9999 --gid=9999
reboot

%packages --nobase
@core
gcc
gcc-c++
kernel-devel
make
net-tools
ntp
patch
sudo
-biosdevname
%end

%post
groupadd -g 9999 vagrant
useradd -u 9999 -g vagrant -G wheel vagrant
echo "vagrant" | passwd --stdin vagrant
sed -E -i '/Defaults[[:space:]]+requiretty/ s/^/#/' /etc/sudoers
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
%end
60 changes: 60 additions & 0 deletions rhel-7.0-vbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"variables": {
"vm_name": "rhel-7.0-vbox",
"iso_url": "{{env `ISO_LOCATION`}}/rhel-server-7.0-x86_64-dvd.iso",
"iso_sha256": "85a9fedc2bf0fc825cc7817056aa00b3ea87d7e111e0cf8de77d3ba643f8646c",
"guest_url": "{{env `ISO_LOCATION`}}",
"guest_sha256": "2a87971ae3c7e57e87713967a6f242acbdafcc09b635cba98e6dd3a7f5292d3b"
},

"builders": [{
"type": "virtualbox-iso",
"guest_os_type": "RedHat_64",
"vm_name": "{{user `vm_name`}}",
"disk_size": "8192",
"vboxmanage": [
["modifyvm", "{{.Name}}", "--memory", "1024"],
["modifyvm", "{{.Name}}", "--cpus", "2"],
["modifyvm", "{{.Name}}", "--ioapic", "on"],
["modifyvm", "{{.Name}}", "--pae", "on"],
["modifyvm", "{{.Name}}", "--rtcuseutc", "on"],
["modifyvm", "{{.Name}}", "--bioslogodisplaytime", "1"]
],
"iso_checksum_type": "sha256",
"iso_url": "{{user `iso_url`}}",
"iso_checksum": "{{user `iso_sha256`}}",
"guest_additions_url": "{{user `guest_url`}}/VBoxGuestAdditions_{{.Version}}.iso",
"guest_additions_sha256": "{{user `guest_sha256`}}",
"guest_additions_path": "/tmp/VBoxGuestAdditions_{{.Version}}.iso",
"virtualbox_version_file": ".virtualbox-version",
"http_directory": "http",
"ssh_wait_timeout": "20m",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"shutdown_command": "echo 'vagrant'|sudo -S /sbin/halt -h -p",
"boot_wait": "5s",
"boot_command": [
"<esc><wait>",
"vmlinuz initrd=initrd.img net.ifnames=0 biosdevname=0 ",
"ks=http://{{.HTTPIP}}:{{.HTTPPort}}/vbox-ks.cfg",
"<enter>"
]
}],

"provisioners": [{
"type": "shell",
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
"scripts": [
"scripts/vagrant.sh",
"scripts/sshd.sh",
"scripts/virtualbox.sh",
"scripts/cleanup.sh"
]
}],

"post-processors": [{
"type": "vagrant",
"output": "{{user `vm_name`}}.box",
"keep_input_artifact": false
}]
}
54 changes: 54 additions & 0 deletions rhel-7.0-vmware.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"variables": {
"vm_name": "rhel-7.0-vmware",
"iso_url": "{{env `ISO_LOCATION`}}/rhel-server-7.0-x86_64-dvd.iso",
"iso_sha256": "85a9fedc2bf0fc825cc7817056aa00b3ea87d7e111e0cf8de77d3ba643f8646c"
},

"builders": [{
"type": "vmware-iso",
"vm_name": "{{user `vm_name`}}",
"guest_os_type": "rhel6-64",
"vmdk_name": "rhel7",
"disk_size": "8192",
"vmx_data": {
"numvcpus": 2,
"memsize": 1024,
"ethernet0.virtualDev": "vmxnet3",
"virtualHW.version": "10"
},
"iso_checksum_type": "sha256",
"iso_url": "{{user `iso_url`}}",
"iso_checksum": "{{user `iso_sha256`}}",
"tools_upload_flavor": "linux",
"tools_upload_path": "/tmp/vmware_tools_{{.Flavor}}.iso",
"http_directory": "http",
"ssh_wait_timeout": "20m",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"shutdown_command": "echo 'vagrant' | sudo -S /sbin/halt -h -p",
"boot_wait": "5s",
"boot_command": [
"<esc><wait>",
"vmlinuz initrd=initrd.img net.ifnames=0 biosdevname=0 ",
"ks=http://{{.HTTPIP}}:{{.HTTPPort}}/vmware-ks.cfg",
"<enter>"
]
}],

"provisioners": [{
"type": "shell",
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
"scripts": [
"scripts/vagrant.sh",
"scripts/vmware.sh",
"scripts/sshd.sh",
"scripts/cleanup.sh"
]
}],

"post-processors": [{
"type": "vagrant",
"output": "{{user `vm_name`}}.box"
}]
}
51 changes: 51 additions & 0 deletions scripts/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -x

# Remove traces of MAC address and UUID from network configuration
sed -E -i '/^(HWADDR|UUID)/d' /etc/sysconfig/network-scripts/ifcfg-e*

# Disable udev network rules
ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules

# Lock root account
passwd -d root
passwd -l root

# Clean up yum
rpm --rebuilddb
yum clean all

# Remove ssh host keys
rm -rf /etc/ssh/ssh_host*_key*

# Clean up /root
rm -f /root/anaconda-ks.cfg
rm -f /root/install.log
rm -f /root/install.log.syslog
rm -rf /root/.pki

# Clean up /var/log
>/var/log/cron
>/var/log/dmesg
>/var/log/lastlog
>/var/log/maillog
>/var/log/messages
>/var/log/secure
>/var/log/wtmp
>/var/log/audit/audit.log
>/var/log/rhsm/rhsm.log
>/var/log/rhsm/rhsmcertd.log
rm -f /var/log/*.old
rm -f /var/log/*.log
rm -f /var/log/*.syslog

# Clean /tmp
rm -rf /tmp/*
rm -rf /tmp/*.*

# Zero out the free space to save space in the final image
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY

# Clear history
history -c
6 changes: 6 additions & 0 deletions scripts/sshd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -x

echo "Modifying /etc/ssh/sshd_config..."
echo "UseDNS no" >> /etc/ssh/sshd_config
echo "GSSAPIAuthentication no" >> /etc/ssh/sshd_config
9 changes: 9 additions & 0 deletions scripts/vagrant.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -x

echo "Adding the vagrant ssh public key..."

mkdir /home/vagrant/.ssh
curl -Lo /home/vagrant/.ssh/authorized_keys https://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub
chown -R vagrant /home/vagrant/.ssh
chmod -R go-rwsx /home/vagrant/.ssh
15 changes: 15 additions & 0 deletions scripts/virtualbox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -x

VBOX_VERSION=$(cat .virtualbox-version)
VBOX_ISO=/tmp/VBoxGuestAdditions_$VBOX_VERSION.iso
VBOX_MNTDIR=$(mktemp --tmpdir=/tmp -q -d -t vbox_mnt_XXXXXX)

# Install tools
mount -o loop $VBOX_ISO $VBOX_MNTDIR
yes|sh $VBOX_MNTDIR/VBoxLinuxAdditions.run

# Clean up
umount $VBOX_MNTDIR
rm -rf $VBOX_MNTDIR
rm -f $VBOX_ISO
31 changes: 31 additions & 0 deletions scripts/vmware.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -x

VMWARE_ISO=/tmp/vmware_tools_linux.iso
VMWARE_MNTDIR=$(mktemp --tmpdir=/tmp -q -d -t vmware_mnt_XXXXXX)
VMWARE_TMPDIR=$(mktemp --tmpdir=/tmp -q -d -t vmware_XXXXXX)

# Extract tools
mount -o loop $VMWARE_ISO $VMWARE_MNTDIR
tar zxf $VMWARE_MNTDIR/VMwareTools*.tar.gz -C $VMWARE_TMPDIR
umount $VMWARE_MNTDIR

# Patch HGFS
curl -Lo $VMWARE_TMPDIR/hgfs_patch.tar.gz https://gist.github.com/jmassara/e794a6ed80543d7c75fb/download
tar zxf $VMWARE_TMPDIR/hgfs_patch.tar.gz -C $VMWARE_TMPDIR
cd $VMWARE_TMPDIR/vmware-tools-distrib/lib/modules/source/
tar xf vmhgfs.tar
cd vmhgfs-only
patch inode.c < $VMWARE_TMPDIR/gist*/vmhgfs-d_count-kernel-3.10-tools-9.6.2.patch
cd ..
rm -f vmhgfs.tar
tar cf vmhgfs.tar vmhgfs-only
cd ~

# Install tools
$VMWARE_TMPDIR/vmware-tools-distrib/vmware-install.pl -d

# Clean up
rm -f $VMWARE_ISO
rm -rf $VMWARE_MNTDIR
rm -rf $VMWARE_TMPDIR

0 comments on commit 0cc709d

Please sign in to comment.