Commit 66a317ef authored by Walter Heck's avatar Walter Heck

First stab at a packer build. So far only builds an empty vm with puppet agent...

First stab at a packer build. So far only builds an empty vm with puppet agent installed on CentOS 7.2
parent c5669737
{
"variables":
{
"template_name": "centos-7.2-x86_64-base",
"template_os": "RedHat_64",
"iso_url": "http://mirror.nl.leaseweb.net/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1511.iso",
"iso_checksum": "907e5755f824c5848b9c8efbb484f3cd945e93faa024bad6ba875226f9683b16",
"iso_checksum_type": "sha256",
"memory_size": "512",
"cpu_count": "1",
"provisioner": "ovf",
"required_modules": "puppetlabs-stdlib saz-ssh",
"puppet_repo": "http://yum.puppetlabs.com/el/7/PC1/x86_64/puppetlabs-release-pc1-1.0.0-2.el7.noarch.rpm"
},
"builders": [
{
"name": "{{user `template_name`}}-{{user `provisioner`}}",
"type": "virtualbox-iso",
"boot_command": [
"<tab> <wait>",
"text <wait>",
"ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/x86_64.ks <wait>",
"<enter>"
],
"boot_wait": "10s",
"disk_size": 10240,
"guest_os_type": "{{user `template_os`}}",
"http_directory": "files",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `iso_url`}}",
"ssh_username": "root",
"ssh_password": "puppet",
"ssh_port": 22,
"ssh_wait_timeout": "10000s",
"shutdown_command": "/sbin/halt -h -p",
"virtualbox_version_file": ".vbox_version",
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"{{user `memory_size`}}"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"{{user `cpu_count`}}"
],
[
"modifyvm",
"{{.Name}}",
"--ioapic",
"off"
]
]
}
],
"provisioners": [
{
"type": "shell",
"execute_command": "{{.Vars}} bash '{{.Path}}' {{user `required_modules`}}",
"environment_vars": [
"TEMPLATE={{user `template_name`}}",
"PC_REPO={{user `puppet_repo`}}"
],
"scripts": [
"scripts/bootstrap-aio.sh"
]
},
{
"type": "puppet-masterless",
"execute_command": "{{.FacterVars}} PATH=$PATH:/opt/puppetlabs/puppet/bin /opt/puppetlabs/puppet/bin/puppet apply --verbose --detailed-exitcodes --modulepath='/tmp/packer-puppet-masterless/manifests/modules' {{.ManifestFile}}",
"facter": {
"provisioner": "{{user `provisioner`}}"
},
"manifest_dir": "manifests",
"manifest_file": "manifests/base.pp"
},
{
"type": "shell",
"environment_vars": [
"TEMPLATE={{user `template_name`}}",
"PC_REPO={{user `puppet_repo`}}"
],
"scripts": [
"scripts/cleanup-scrub.sh"
]
}
]
}
install
cdrom
lang en_US.UTF-8
keyboard us
network --bootproto=dhcp
rootpw --iscrypted $1$v4K9E8Wj$gZIHJ5JtQL5ZGZXeqSSsd0
firewall --enabled --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone UTC
bootloader --location=mbr
text
skipx
zerombr
clearpart --all --initlabel
autopart
auth --useshadow --enablemd5
firstboot --disabled
reboot --eject
%packages --ignoremissing
@core
bzip2
kernel-devel
kernel-headers
gcc
make
net-tools
patch
perl
curl
wget
nfs-utils
-ipw2100-firmware
-ipw2200-firmware
-ivtv-firmware
%end
include packer::updates
include packer::sshd
include packer::networking
unless $::provisioner == 'ec2' {
include packer::vmtools
}
include packer::puppet
include packer::vagrant
#!/bin/bash
# create a directory for the local puppet module used to provision some of this machine
tmp_dir="/tmp/packer-puppet-masterless"
mkdir -p "$tmp_dir"
# Download and install puppet-agent from the release repo
if [ -n "${PC_REPO}" ]; then
echo "Downloading and installing AIO from repo..."
# Determine if this is RPM or DEB and Do the Right Thing (tm)
if [[ ${PC_REPO} == *".rpm"* ]] ; then
curl --silent "${PC_REPO}" -o $tmp_dir/pc-repo.rpm
rpm -Uhv $tmp_dir/pc-repo.rpm
if type dnf >/dev/null ; then
dnf install -y puppet-agent
else
yum install -y puppet-agent
fi
elif [[ ${PC_REPO} == *".deb"* ]] ; then
curl --silent "${PC_REPO}" -o $tmp_dir/pc-repo.deb
dpkg -i $tmp_dir/pc-repo.deb
apt-get update
apt-get install -y puppet-agent
else
echo "Unsupported AIO package format" >&2
exit 1
fi
else
echo "The environment variable PC_REPO must be provided to provision AIO." >&2
exit 1
fi
# Show Puppet version
printf 'Puppet ' ; /opt/puppetlabs/puppet/bin/puppet --version
# Installed required modules
for i in "$@"
do
/opt/puppetlabs/puppet/bin/puppet module install $i --modulepath=/tmp/packer-puppet-masterless/manifests/modules >/dev/null 2>&1
done
# Print some diagnostic information
printf 'Modules installed in ' ; /opt/puppetlabs/puppet/bin/puppet module list --modulepath=/tmp/packer-puppet-masterless/manifests/modules
#!/bin/bash
# AIO puppet-agent is currently used to provision nocm and puppet boxes.
# This script cleans up directories that may be left around
# as part of that process.
# Uninstall the AIO
if [[ ${PC_REPO} == *".rpm"* ]] ; then
rpm -e puppet-agent
rpm -e puppetlabs-release-pc1
elif [[ ${PC_REPO} == *".deb"* ]] ; then
dpkg -P puppet-agent
else
echo "Unsupported AIO package format" >&2
exit 1
fi
# Remove any Puppet-related files and directories
rm -rf /etc/puppetlabs
rm -rf /opt/puppetlabs
#!/bin/bash
# Clear wtmp
cat /dev/null > /var/log/wtmp
# Remove this script
rm -rf /tmp/script.sh
# Remove Packer-related files and directories
rm -rf /tmp/packer-puppet-masterless
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment