Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
Shell script to create a Vagrant shell to be customized later. Uses puppet provisioner for CentOS 6.x
# Creates basic Vagrant/Puppet setup.
# Assumes you have vagrant installed already
# requires one argument, name of the directory to store Vagrant config
# ./ linux-server
# can't continue without git
which git || (echo "can't find git"; exit 1)
# make directory structure
mkdir -p $1/{keys,manifest,puppet/modules,puppet/hiera}
# Puppetfile used for r10k
# put your required modules here
touch $1/puppet/Puppetfile
# default.pp used by Puppet to assign roles/modules to server
# add your node definitions here
touch $1/manifests/default.pp
# add .gitignore to these directories so git will keep them in the repository
# contents of modules will be wiped out and rebuilt by r10k
touch .gitignore $1/puppet/modules
# hiera may be empty but we want to keep it around
touch .gitignore $1/puppet/hiera
# store ssh keys here. still want to keep it if we don't have any
touch .gitignore $1/keys
# create default hiera.yaml
cat > $1/hiera.yaml << EOF
- yaml
:datadir: ./
- "node/%{::fqdn}"
- common
# create ssh key for vagrant user
# if you replaced the Vagrant default private key
#cat > $1/keys/id_rsa_vagrant << EOF
# create vagrant file
cat > $1/Vagrantfile << EOF
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
# list all servers to build
servers = [ 'server' ]
# set domain name for servers
domain = 'domain.local'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# set box to use = "centos64-64bit"
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
v.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
v.customize ["modifyvm", :id, "--memory", 1024]
v.auto_nat_dns_proxy = false
# basebox centos64-64bit has unique private key installed
config.ssh.private_key_path = "keys/id_rsa_vagrant"
# the parent directory that contains your module directory and Puppetfile
config.r10k.puppet_dir = 'puppet'
# the path to your Puppetfile, within the repo
config.r10k.puppetfile_path = 'puppet/Puppetfile'
servers.each do |server|
config.vm.define server do |server_config|
# puppet agent install bootstrap executed by Vagrant with shell provisioner
server_config.vm.provision "shell", path: "./puppet-bootstrap/"
# sync hiera config directory with guest
server_config.vm.synced_folder "puppet/hiera", '/tmp/vagrant-hiera'
# set host name
server_config.vm.host_name = server + '.' + domain
# provision each server with puppet
server_config.vm.provision "puppet" do |puppet|
# set hiera configuration path
puppet.hiera_config_path = 'hiera.yaml'
# set module path
puppet.module_path = "puppet/modules"
# set working directory to our sync'd folder
# this will allow puppet to pick up hiera data
puppet.working_directory = '/tmp/vagrant-hiera'
# lots of output for debugging, noisy!
puppet.options = "--verbose --debug"
# create a basic README
cat > $1/README << EOF
$1 Vagrant
created by `whoami`
# set up new vagrant directory for git
cd $1
git init
git add .
# add puppet bootstrap as a submodule
git submodule add
# perform an initial commit
git commit -m "initial commit for $1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment