Skip to content

added local yum repo hosting on puppet server when started as centos #6

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

Open
wants to merge 5 commits 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
nodes.pp
modules/*
.vagrant
packages/rpm/*
!packages/rpm/README.md
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
---------------
Expand Down Expand Up @@ -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
=======

Expand Down
39 changes: 0 additions & 39 deletions Vagrantfile

This file was deleted.

1 change: 1 addition & 0 deletions Vagrantfile
40 changes: 40 additions & 0 deletions Vagrantfile.centos63
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions Vagrantfile.precise64
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions packages/rpm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# RPMs go here
5 changes: 5 additions & 0 deletions provision/manifests/default.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@

if $hostname == 'puppet' {
class { 'puppet::server': }
class { 'repository::server': }
} elsif $hostname == 'fpm' {
class { 'fpm': }
} else {
class { 'repository::client': stage => 'pre' }
}
63 changes: 63 additions & 0 deletions provision/modules/fpm/files/elasticsearch-rpm.sh
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions provision/modules/fpm/files/redis-rpm.sh
Original file line number Diff line number Diff line change
@@ -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/ .


49 changes: 49 additions & 0 deletions provision/modules/fpm/manifests/centos.pp
Original file line number Diff line number Diff line change
@@ -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',
}


}
19 changes: 19 additions & 0 deletions provision/modules/fpm/manifests/debian.pp
Original file line number Diff line number Diff line change
@@ -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"],
}
}
14 changes: 14 additions & 0 deletions provision/modules/fpm/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -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}")
}
}

}
1 change: 1 addition & 0 deletions provision/modules/networking/templates/hosts.erb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading