Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vagrant support with automatic provision of the code #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,40 @@ If you have questions regarding how to use this module, don't hesitate to fill a

Contribution must not raise errors from puppet-lint.

You can use [Vagrant](https://www.vagrantup.com) and [Virtualbox](https://www.virtualbox.org)
for testing and developing this module. Currently the Vagrantfile creates an Ubuntu 18.04 VM
("samba-bionic") and runs provisioning steps that

* Install Puppet 5 from Puppetlabs
* Fetch this module's dependencies with [librarian-puppet](https://librarian-puppet.com) based on metadata.json
* Runs a Puppet manifest (simple_share.pp) with "puppet apply"

The Puppet manifest sets up a standalone "classic" Samba server, creates one share and a user that
can read and write to that share. Username is "vagrant" and password is "vagrant" for both Linux and
Samba.

To create or start the VM:

$ vagrant up

To (re)provision the VM, usually to test new puppet code:

$ vagrant provision

To shut down the VM:

$ vagrant halt

To destroy the VM:

$ vagrant destroy

If you want to test some particular Samba setup you can create a custom Puppet manifest and point
your Vagrantfile to it. After the VM has been created you can comment out the prepare.sh
provisioning step in the Vagranfile to speed up Puppet code testing.

See [Vagrant documentation](https://www.vagrantup.com/docs/index.html) for details.

## Release Notes


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/simple_share.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
36 changes: 36 additions & 0 deletions vagrant/simple_share.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package { 'smbclient':
ensure => 'present',
}

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

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

# Add a local SMB test user
exec { 'add-smb-user':
# See https://stackoverflow.com/questions/12009/piping-password-to-smbpasswd/53428249
command => 'yes vagrant|head -n 2|smbpasswd -a -s vagrant',
unless => "pdbedit -L|grep \"^vagrant:\"",
path => ['/bin', '/usr/bin'],
}