diff --git a/.gitignore b/.gitignore index e9a7b8a..f9d66e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ nodes.pp modules/* .vagrant +packages/rpm/* +!packages/rpm/README.md diff --git a/README.md b/README.md index 10a6ec8..e608503 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,10 @@ environment and tools. Puppet Sandbox will set up three separate virtual machines: -* _puppet.example.com_ - the Puppet master server +* _puppet.example.com_ - the Puppet master server * _client1.example.com_ - the first Puppet client machine * _client2.example.com_ - the second Puppet client machine +* _fpm.example.com_ - package building machine These VMs can be used in conjunction to segregate and test your modules based on node roles, Puppet environments, etc. You can even test modules @@ -53,6 +54,9 @@ should be good to clone this repo and go: If you want a CentOS base box to work from, I highly recommend the boxes published by Jan Vansteenkiste: http://packages.vstone.eu/vagrant-boxes/ +if using other CentOS boxes watch out for iptables being turned on by default. + +The Vagrantfile is a symlink to either Vagrantfile.precise64 or Vagrantfile.centos63. Initial Startup --------------- @@ -116,6 +120,39 @@ the agent daemon, you can easily force a manual run: [vagrant@client1 ~]$ sudo puppet agent --test + +Package Repositories +-------------------- + +A local YUM repo `sandbox` is configured on the puppet server. Copy RPM files into `/vagrant/packages/rpm` and then run `vagrant provision puppet` to refresh the repo. Currently only supports RPM/YUM but will add APT support some time soon. + +Building Packages +----------------- + +FPM is installed on the fpm host. This is an excellent tool for building OS packages where writing specfiles gets painful. FPM allows you to create RPM or APT packages from source, or from a directory with all the apps installed. Check the example redis or elasticsearch scripts on the FPM system under /tmp/ for examples of building packages using FPM. Saving the resultant RPM to `/vagrant/packages/rpm` and run `vagrant provision puppet` will make it immediately available to client1,client2 for installation. + +Example Package Building and Usage +---------------------------------- + + $ vagrant up puppet fpm client1 + $ vagrant ssh fpm + [vagrant@fpm ~]$ sudo /tmp/redis-rpm.sh + ... + ... + [vagrant@fpm ~]$ exit + $ vagrant provision puppet + $ vagrant ssh client1 + [vagrant@client1 ~]$ sudo yum clean all + [vagrant@client1 ~]$ sudo yum -y install redis + [vagrant@client1 ~]$ sudo service redis-server start + [vagrant@client1 ~]$ redis-cli ping + PONG + [vagrant@client1 ~]$ + + + + + License ======= diff --git a/Vagrantfile b/Vagrantfile deleted file mode 100644 index b42906f..0000000 --- a/Vagrantfile +++ /dev/null @@ -1,39 +0,0 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - -domain = 'example.com' - -puppet_nodes = [ - {:hostname => 'puppet', :ip => '172.16.32.10', :box => 'precise64', :fwdhost => 8140, :fwdguest => 8140, :ram => 512}, - {:hostname => 'client1', :ip => '172.16.32.11', :box => 'precise64'}, - {:hostname => 'client2', :ip => '172.16.32.12', :box => 'precise64'}, -] - -Vagrant.configure("2") do |config| - puppet_nodes.each do |node| - config.vm.define node[:hostname] do |node_config| - node_config.vm.box = node[:box] - node_config.vm.box_url = 'http://files.vagrantup.com/' + node_config.vm.box + '.box' - node_config.vm.hostname = node[:hostname] + '.' + domain - node_config.vm.network :private_network, ip: node[:ip] - - if node[:fwdhost] - node_config.vm.network :forwarded_port, guest: node[:fwdguest], host: node[:fwdhost] - end - - memory = node[:ram] ? node[:ram] : 256; - node_config.vm.provider :virtualbox do |vb| - vb.customize [ - 'modifyvm', :id, - '--name', node[:hostname], - '--memory', memory.to_s - ] - end - - node_config.vm.provision :puppet do |puppet| - puppet.manifests_path = 'provision/manifests' - puppet.module_path = 'provision/modules' - end - end - end -end diff --git a/Vagrantfile b/Vagrantfile new file mode 120000 index 0000000..a4cdb05 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1 @@ +Vagrantfile.centos63 \ No newline at end of file diff --git a/Vagrantfile.centos63 b/Vagrantfile.centos63 new file mode 100644 index 0000000..5a09393 --- /dev/null +++ b/Vagrantfile.centos63 @@ -0,0 +1,40 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +domain = 'example.com' + +puppet_nodes = [ + {:hostname => 'fpm', :ip => '172.16.32.9', :box => 'centos63'}, + {:hostname => 'puppet', :ip => '172.16.32.10', :box => 'centos63', :fwdhost => 8140, :fwdguest => 8140, :ram => 512}, + {:hostname => 'client1', :ip => '172.16.32.11', :box => 'centos63'}, + {:hostname => 'client2', :ip => '172.16.32.12', :box => 'centos63'}, +] + +Vagrant.configure("2") do |config| + puppet_nodes.each do |node| + config.vm.define node[:hostname] do |node_config| + node_config.vm.box = node[:box] + node_config.vm.box_url = 'http://files.vagrantup.com/' + node_config.vm.box + '.box' + node_config.vm.hostname = node[:hostname] + '.' + domain + node_config.vm.network :private_network, ip: node[:ip] + + if node[:fwdhost] + node_config.vm.network :forwarded_port, guest: node[:fwdguest], host: node[:fwdhost] + end + + memory = node[:ram] ? node[:ram] : 256; + node_config.vm.provider :virtualbox do |vb| + vb.customize [ + 'modifyvm', :id, + '--name', node[:hostname], + '--memory', memory.to_s + ] + end + + node_config.vm.provision :puppet do |puppet| + puppet.manifests_path = 'provision/manifests' + puppet.module_path = 'provision/modules' + end + end + end +end diff --git a/Vagrantfile.precise64 b/Vagrantfile.precise64 new file mode 100644 index 0000000..1124cb8 --- /dev/null +++ b/Vagrantfile.precise64 @@ -0,0 +1,40 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +domain = 'example.com' + +puppet_nodes = [ + {:hostname => 'fpm', :ip => '172.16.32.9', :box => 'precise64'}, + {:hostname => 'puppet', :ip => '172.16.32.10', :box => 'precise64', :fwdhost => 8140, :fwdguest => 8140, :ram => 512}, + {:hostname => 'client1', :ip => '172.16.32.11', :box => 'precise64'}, + {:hostname => 'client2', :ip => '172.16.32.12', :box => 'precise64'}, +] + +Vagrant.configure("2") do |config| + puppet_nodes.each do |node| + config.vm.define node[:hostname] do |node_config| + node_config.vm.box = node[:box] + node_config.vm.box_url = 'http://files.vagrantup.com/' + node_config.vm.box + '.box' + node_config.vm.hostname = node[:hostname] + '.' + domain + node_config.vm.network :private_network, ip: node[:ip] + + if node[:fwdhost] + node_config.vm.network :forwarded_port, guest: node[:fwdguest], host: node[:fwdhost] + end + + memory = node[:ram] ? node[:ram] : 256; + node_config.vm.provider :virtualbox do |vb| + vb.customize [ + 'modifyvm', :id, + '--name', node[:hostname], + '--memory', memory.to_s + ] + end + + node_config.vm.provision :puppet do |puppet| + puppet.manifests_path = 'provision/manifests' + puppet.module_path = 'provision/modules' + end + end + end +end diff --git a/packages/rpm/README.md b/packages/rpm/README.md new file mode 100644 index 0000000..08c3651 --- /dev/null +++ b/packages/rpm/README.md @@ -0,0 +1 @@ +# RPMs go here diff --git a/provision/manifests/default.pp b/provision/manifests/default.pp index d820c12..4ffda8e 100644 --- a/provision/manifests/default.pp +++ b/provision/manifests/default.pp @@ -12,4 +12,9 @@ if $hostname == 'puppet' { class { 'puppet::server': } + class { 'repository::server': } +} elsif $hostname == 'fpm' { + class { 'fpm': } +} else { + class { 'repository::client': stage => 'pre' } } diff --git a/provision/modules/fpm/files/elasticsearch-rpm.sh b/provision/modules/fpm/files/elasticsearch-rpm.sh new file mode 100755 index 0000000..e6282f5 --- /dev/null +++ b/provision/modules/fpm/files/elasticsearch-rpm.sh @@ -0,0 +1,63 @@ +#!/bin/bash -x + +#install pre-reqs +#yum -y install java-1.7.0-openjdk + +# ElasticSearch! +VERSION=0.20.5 +PREFIX=/opt +ES_DIR=$PREFIX/elasticsearch +ES_USER=elasticsearch +ULIMIT=80000 + +cd $PREFIX +curl -L -k https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$VERSION.tar.gz | tar -xz +mv elasticsearch-$VERSION elasticsearch +cd elasticsearch/bin/ +curl -L -k http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master | tar -xz +mv *servicewrapper*/service $ES_DIR/bin/ +mkdir -p $ES_DIR/extras + +$ES_DIR/bin/plugin -install elasticsearch/elasticsearch-river-rabbitmq/1.4.0 +$ES_DIR/bin/plugin -install lukas-vlcek/bigdesk +$ES_DIR/bin/plugin -install karmi/elasticsearch-paramedic +$ES_DIR/bin/plugin -install mobz/elasticsearch-head + +#### GRRRR init script fails when launching as user other than root. too lazy to work out why right now. +#sed -i "s/^.*RUN_AS_USER=.*/RUN_AS_USER=$ES_USER/" /opt/elasticsearch/bin/service/elasticsearch +sed -i "s/^.*ULIMIT_N=.*/ULIMIT_N=$ULIMIT/" /opt/elasticsearch/bin/service/elasticsearch + +cat > $ES_DIR/extras/elasticsearch-post-install.sh << EOF +#!/bin/sh + +adduser $ES_USER +chown -R $ES_USER:$ES_USER $ES_DIR +$ES_DIR/bin/service/elasticsearch install +ln -s `readlink -f $ES_DIR/bin/service/elasticsearch` /usr/local/bin/rcelasticsearch +EOF + +chmod 755 $ES_DIR/extras/elasticsearch-post-install.sh + +cat > $ES_DIR/extras/elasticsearch-pre-uninstall.sh << EOF +#!/bin/sh + +userdel elasticsearch +/opt/elasticsearch/bin/service/elasticsearch remove +rm -f /usr/local/bin/rcelasticsearch +EOF + +chmod 755 $ES_DIR/extras/elasticsearch-pre-uninstall.sh + +cd /vagrant/packages/rpm/ + +fpm -s dir -t rpm -d 'java-1.7.0-openjdk' --post-install "$ES_DIR/extras/elasticsearch-post-install.sh" \ + --pre-uninstall "$ES_DIR/extras/elasticsearch-pre-uninstall.sh" -n "elasticsearch" -v $VERSION $ES_DIR + +# echo ... lets fire it up and see if it works. +#adduser $ES_USER +#chown -R $ES_USER:$ES_USER $ES_DIR +#$ES_DIR/bin/service/elasticsearch install +#ln -s `readlink -f $ES_DIR/bin/service/elasticsearch` /usr/local/bin/rcelasticsearch +#service elasticsearch start +#sleep 5 +#curl http://localhost:9200 diff --git a/provision/modules/fpm/files/redis-rpm.sh b/provision/modules/fpm/files/redis-rpm.sh new file mode 100755 index 0000000..4c8fb4a --- /dev/null +++ b/provision/modules/fpm/files/redis-rpm.sh @@ -0,0 +1,33 @@ +#!/bin/bash -x + +VERSION=2.6.11 +PREFIX=/ + +cd /tmp +curl -L -k http://redis.googlecode.com/files/redis-$VERSION.tar.gz| tar -xz +cd redis-$VERSION +make +# should probably run the test .... +#make test + +mkdir -p /tmp/build-redis-$VERSION/$PREFIX/usr/bin +mkdir -p /tmp/build-redis-$VERSION/$PREFIX/etc/init.d +mkdir -p /tmp/build-redis-$VERSION/$PREFIX/etc/redis + +cp src/{redis-benchmark,redis-check-aof,redis-check-dump,redis-cli,redis-server} /tmp/build-redis-$VERSION/$PREFIX/usr/bin + +cp redis.conf /tmp/build-redis-$VERSION/$PREFIX/etc/redis/redis.conf + +sed -i "s/daemonize no/daemonize yes/" /tmp/build-redis-$VERSION/$PREFIX/etc/redis/redis.conf + +curl -L -k https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server > /tmp/build-redis-$VERSION/$PREFIX/etc/init.d/redis-server + +chmod 755 /tmp/build-redis-$VERSION/$PREFIX/etc/init.d/redis-server + +sed -i "s|/usr/local/sbin/redis-server|/usr/bin/redis-server|" /tmp/build-redis-$VERSION/$PREFIX/etc/init.d/redis-server + +cd /vagrant/packages/rpm/ + +fpm -s dir -t rpm -n redis -v $VERSION -C /tmp/build-redis-$VERSION/ . + + diff --git a/provision/modules/fpm/manifests/centos.pp b/provision/modules/fpm/manifests/centos.pp new file mode 100644 index 0000000..9c7cdba --- /dev/null +++ b/provision/modules/fpm/manifests/centos.pp @@ -0,0 +1,49 @@ +#yum -y install ruby rubygems ruby-devel make gcc rpm-build git +# gem install fpm + +class fpm::centos { + package { 'ruby-devel': + ensure => 'present', + } + package { 'rubygems': + ensure => 'present', + } + package { 'make': + ensure => 'present', + } + package { 'gcc': + ensure => 'present', + } + package { 'rpm-build': + ensure => 'present', + } + package { 'git': + ensure => 'present', + } + package { 'fpm': + ensure => 'present', + provider => 'gem', + require => [ Package["rubygems"], Package["ruby-devel"] ], + } + +file { 'redis-rpm.sh': + ensure => present, + path => '/tmp/redis-rpm.sh', + owner => vagrant, + group => vagrant, + mode => '0755', + replace => true, + source => 'puppet:///modules/fpm/redis-rpm.sh', + } +file { 'elasticsearch-rpm.sh': + ensure => present, + path => '/tmp/elasticsearch-rpm.sh', + owner => vagrant, + group => vagrant, + mode => '0755', + replace => true, + source => 'puppet:///modules/fpm/elasticsearch-rpm.sh', + } + + +} \ No newline at end of file diff --git a/provision/modules/fpm/manifests/debian.pp b/provision/modules/fpm/manifests/debian.pp new file mode 100644 index 0000000..18f14f8 --- /dev/null +++ b/provision/modules/fpm/manifests/debian.pp @@ -0,0 +1,19 @@ +class fpm::debian { + package { 'rubygems': + ensure => 'present', + } + package { 'make': + ensure => 'present', + } + package { 'gcc': + ensure => 'present', + } + package { 'git': + ensure => 'present', + } + package { 'fpm': + ensure => 'present', + provider => 'gem', + require => Package["rubygems"], + } +} \ No newline at end of file diff --git a/provision/modules/fpm/manifests/init.pp b/provision/modules/fpm/manifests/init.pp new file mode 100644 index 0000000..9a6b7d9 --- /dev/null +++ b/provision/modules/fpm/manifests/init.pp @@ -0,0 +1,14 @@ +class fpm { + case $::osfamily { + 'redhat': { + class { 'fpm::centos': } + } + 'debian': { + class { 'fpm::debian': } + } + default: { + #fail("Module '${module_name}' is not currently supported by Puppet Sandbox on ${::operatingsystem}") + } + } + +} \ No newline at end of file diff --git a/provision/modules/networking/templates/hosts.erb b/provision/modules/networking/templates/hosts.erb index d353e2c..ac9db6d 100644 --- a/provision/modules/networking/templates/hosts.erb +++ b/provision/modules/networking/templates/hosts.erb @@ -1,6 +1,7 @@ 127.0.0.1 localhost 127.0.1.1 <%= fqdn %> +172.16.32.9 fpm.<%= domain %> fpm 172.16.32.10 puppet.<%= domain %> puppet 172.16.32.11 client1.<%= domain %> client1 172.16.32.12 client2.<%= domain %> client2 diff --git a/provision/modules/repository/files/index.html b/provision/modules/repository/files/index.html new file mode 100644 index 0000000..dd1a2cd --- /dev/null +++ b/provision/modules/repository/files/index.html @@ -0,0 +1,9 @@ + +
+