diff --git a/.gitignore b/.gitignore index 8f25143..9179bb8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,10 @@ /test/version_tmp/ /tmp/ +## Specific to Vagrant: +.vagrant +ubuntu-*-cloudimg-console.log + ## Specific to RubyMotion: .dat* .repl_history diff --git a/README.md b/README.md index f28828c..0438acf 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..15b5e6f --- /dev/null +++ b/Vagrantfile @@ -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 diff --git a/vagrant/prepare.sh b/vagrant/prepare.sh new file mode 100644 index 0000000..367e324 --- /dev/null +++ b/vagrant/prepare.sh @@ -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 diff --git a/vagrant/simple_share.pp b/vagrant/simple_share.pp new file mode 100644 index 0000000..3625c74 --- /dev/null +++ b/vagrant/simple_share.pp @@ -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'], +}