Skip to content

Instantly share code, notes, and snippets.

% 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 October 14, 2010 23:32
set an exported resource
# 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 October 15, 2010 00:06
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.
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 October 15, 2010 19:56
Simplest example of a masterless puppet invocation using module paths
include foo
@jordansissel
jordansissel / up function
Created October 19, 2010 00:34
cd ../../../foo/bar is boring. 'up 3 foo/bar'
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 October 28, 2010 07:22
notify from a file change that is not managed by puppet
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 October 29, 2010 17:41
Hack puppet to do stuff over ssh.
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 October 29, 2010 18:09
puppetless puppet (package management of remote hosts)
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 October 30, 2010 10:06
Using the puppet config parser for a configfile in your own project.
#!/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 November 10, 2010 08:39
grok with ffi in ruby and jruby
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.