Skip to content

Instantly share code, notes, and snippets.

Avatar

Jordan Sissel jordansissel

View GitHub Profile
View output
% sudo ruby ruby-supervisorctl.rb
[
[0] [
[0] {
:state => 30,
:stdout_logfile => "/tmp/falsetest-stdout---supervisor-bqdUwO.log",
:now => 1286783537,
:start => 1286783530,
:group => "falsetest",
@jordansissel
jordansissel / Running it
Created Oct 14, 2010
set an exported resource
View Running it
# The first run fails because there is no 'importantserver' placeholder resource.
frontend1(~) % puppet apply --storeconfigs --config ./puppet.conf pull.pp
Could not find dependency Placeholder[importantserver] for File[/tmp/y] at /home/jordan/pull.pp:12
# Have another server export this resource
ops(~/pp) % puppet apply --storeconfigs --config ./puppet.conf push.pp
# Try again, which works because the exported resource is found.
frontend1(~) !1! % puppet apply --storeconfigs --config ./puppet.conf pull.pp
notice: /Stage[main]/Bar/File[/tmp/y]/content: content changed '{md5}5a2f711ba4198f0db5e6b9e38a8f2d64' to '{md5}53cadf1c93f077aae3747e6507d7aa8e'
@jordansissel
jordansissel / pull.pp
Created Oct 15, 2010
more detailed hack attempt at making only part of the puppet graph fail when an exported resource doesn't exist yet. Doesn't work since (thankfully) puppet doesn't let oyu override local resources with exported ones.
View pull.pp
define placeholder($ready) {
# Nothing to do, it's a placeholder!
}
class bar {
/* Should override the above */
$placeholder = "superserver"
placeholder {
"$placeholder":
ready => false;
@jordansissel
jordansissel / site.pp
Created Oct 15, 2010
Simplest example of a masterless puppet invocation using module paths
View site.pp
include foo
@jordansissel
jordansissel / up function
Created Oct 19, 2010
cd ../../../foo/bar is boring. 'up 3 foo/bar'
View up function
up () {
if [ "$#" -eq 0 ]
then
echo "Up to where?"
return 1
fi
times=$1
target="$2"
while [ $times -gt 0 ]
do
@jordansissel
jordansissel / example usage:
Created Oct 28, 2010
notify from a file change that is not managed by puppet
View example usage:
snack(~) % rm /tmp/flag
snack(~) % echo "Hello" > /tmp/original
snack(~) % sudo puppet apply unmanaged-notify.pp
notice: /Stage[main]//File[/tmp/flag]/ensure: defined content as '{md5}09f7e02f1290be211da707a266f153b3'
notice: /Stage[main]//Exec[hello world]: Triggered 'refresh' from 1 events
# Won't exec 'hello world' again because no change occured to /tmp/original:
snack(~) % sudo puppet apply unmanaged-notify.pp
# Now change /tmp/original:
@jordansissel
jordansissel / output
Created Oct 29, 2010
Hack puppet to do stuff over ssh.
View output
snack(~) % ruby puppet-package-over-ssh.rb snack apache2.2-common latest
Package[apache2.2-common] ensure => latest status: {:status=>"installed", :provider=>:apt, :error=>"ok", :desired=>"install", :name=>"apache2.2-common", :ensure=>"2.2.14-5ubuntu8.3"}
snack(~) % ruby puppet-package-over-ssh.rb snack sl latest
Package[sl] ensure => latest status: {:status=>"installed", :provider=>:apt, :error=>"ok", :desired=>"install", :name=>"sl", :ensure=>"3.03-16"}
# There's a bug where 'latest' seems to be ignored. If you try to use 'absent' it still installs anyway. I'm not familiar with puppet internals so this bug should be easy to fix.
snack(~) % ruby puppet-package-over-ssh.rb snack sl absent
Package[sl] ensure => absent status: {:status=>"installed", :provider=>:apt, :error=>"ok", :desired=>"install", :name=>"sl", :ensure=>"3.03-16"}
@jordansissel
jordansissel / output
Created Oct 29, 2010
puppetless puppet (package management of remote hosts)
View output
Usage: puppet-package-over-ssh.rb HOST PACKAGE ACTION
% ruby puppet-package-over-ssh.rb snack sl uninstall
Package[sl] uninstall status: {:status=>"not-installed", :error=>"ok", :desired=>"unknown", :ensure=>:purged, :name=>"sl", :provider=>:apt}
% ruby puppet-package-over-ssh.rb snack sl install
Package[sl] install status: {:status=>"installed", :error=>"ok", :desired=>"install", :ensure=>"3.03-16", :name=>"sl", :provider=>:apt}
% ruby puppet-package-over-ssh.rb snack fancypants install
Could not install package Package[fancypants]: Execution of 'ssh snack sudo "/usr/bin/apt-get" "-q" "-y" "-o" "DPkg::Options::=--force-confold" "install" "fancypants"' returned 100: Reading package lists...
Building dependency tree...
@jordansissel
jordansissel / puppet-parser-elsewhere.rb
Created Oct 30, 2010
Using the puppet config parser for a configfile in your own project.
View puppet-parser-elsewhere.rb
#!/usr/bin/env ruby
#
require "rubygems"
require "puppet" # gem puppet
require "ap" # gem awesome_print
# Need to define a type for each type we want to have.
# Otherwise, unknown types are errors in puppet.
Puppet::Type.newtype(:input) do
@jordansissel
jordansissel / grokffi.rb
Created Nov 10, 2010
grok with ffi in ruby and jruby
View grokffi.rb
require "rubygems"
require "ffi"
module Grok
extend FFI::Library
ffi_lib "grok.so"
# class for grok_t
# Attributes with '__' prefixes are not for your consumption; they
# are internal to libgrok.
You can’t perform that action at this time.