Skip to content

Commit

Permalink
Add Vagrant support with automatic provision of the code
Browse files Browse the repository at this point in the history
Signed-off-by: Samuli Seppänen <[email protected]>
  • Loading branch information
mattock committed Nov 22, 2018
1 parent 7ce3dd4 commit 9df6007
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
/test/version_tmp/
/tmp/

## Specific to Vagrant:
.vagrant
ubuntu-*-cloudimg-console.log

## Specific to RubyMotion:
.dat*
.repl_history
Expand Down
22 changes: 22 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

config.vm.define "samba-bionic" do |box|
box.vm.box = "ubuntu/bionic64"
box.vm.box_version = "20180919.0.0"
box.vm.hostname = "samba-bionic.local"
box.vm.network "private_network", ip: "192.168.153.100"
box.vm.synced_folder ".", "/vagrant", type: "virtualbox"
box.vm.provision "shell" do |s|
s.path = "vagrant/prepare.sh"
s.args = ["-n", "samba", "-f", "debian", "-o", "bionic", "-b", "/home/ubuntu"]
end
box.vm.provision "shell", inline: "puppet apply --modulepath /home/ubuntu/modules /vagrant/vagrant/samba.pp"
box.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.memory = 1280
end
end
end
81 changes: 81 additions & 0 deletions vagrant/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/sh
#
# Preparations required prior to "puppet apply".

usage() {
echo
echo "Usage: prepare.sh -n module_name -f osfamily -o os"
echo
echo "Options:"
echo " -n Name of the module that includes this script. Used to copy"
echo " the module code to the modulepath."
echo " -f Operating system family for this Vagrant VM. Valid values are"
echo " redhat and debian. This determines the logic to use when"
echo " installing Puppet on the nodes."
echo " -o Operating system version. For Debian derivatives use the"
echo " codename (e.g. stretch or xenial). For RedHat derivatives"
echo " use the osname-osversion scheme (e.g. el-7). For details"
echo " see Puppet yum/apt repository documentation"
echo " -b Base directory for dependency Puppet modules installed by"
echo " librarian-puppet."
exit 1
}


# Parse the options

# We are run without parameters -> usage
if [ "$1" == "" ]; then
usage
fi

while getopts "n:f:o:b:h" options; do
case $options in
n ) THIS_MODULE=$OPTARG;;
f ) OSFAMILY=$OPTARG;;
o ) OS=$OPTARG;;
b ) BASEDIR=$OPTARG;;
h ) usage;;
\? ) usage;;
* ) usage;;
esac
done

CWD=`pwd`

install_puppet() {
if [ $OSFAMILY = 'redhat' ]; then
rpm -ivh https://yum.puppetlabs.com/puppet5/puppet5-release-$OS.noarch.rpm
yum install -y puppet-agent yum-utils git
yum-config-manager --save --setopt=puppetlabs-pc1.skip_if_unavailable=true
elif [ $OSFAMILY = 'debian' ]; then
wget https://apt.puppetlabs.com/puppet5-release-$OS.deb -O puppet5-release-$OS.deb
dpkg -i puppet5-release-$OS.deb
apt-get update
apt-get -y install puppet-agent git
else
echo "ERROR: unsupported value ${OSFAMILY} for option -f!"
usage
fi
}

install_puppet

export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/puppet/bin

# Install librarian-puppet with Puppetlabs' gem and not a system gem
/opt/puppetlabs/puppet/bin/gem install librarian-puppet

# Install dependency modules with librarian-puppet
cd $BASEDIR
mkdir -p modules
rm -f $BASEDIR/metadata.json
ln -s /vagrant/metadata.json
librarian-puppet install

# Copy over this in-development module to modules
# directory
rm -f modules/${THIS_MODULE}
ln -s /vagrant modules/${THIS_MODULE}

cd $CWD
25 changes: 25 additions & 0 deletions vagrant/samba.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package { 'smbclient':
ensure => 'present',
}

class { '::samba::classic':
domain => 'vagrant',
realm => 'vagrant.local',
smbname => 'SMB',
security => 'user',
adminuser => 'administrator',
adminpassword => 'vagrant',
join_domain => false,
}

::samba::share { 'share':
path => '/srv/share',
manage_directory => true,
owner => 'root',
group => 'root',
mode => '0775',
acl => [],
options => {
'browsable' => 'Yes',
},
}

0 comments on commit 9df6007

Please sign in to comment.