Skip to content

Instantly share code, notes, and snippets.

@garthk
garthk / fixpup
Created October 9, 2012 00:57 — forked from haus/gist:3851012
Script: pin Puppet to 2.7.* on Ubuntu
#!/bin/sh
# Pin Ubuntu to use Puppet 2.7.* rather than Puppet 3.
# Assumes you're using the Puppet APT repo at apt.puppetlabs.com.
# Thanks to haus for the technique.
cat > /etc/apt/preferences.d/00-puppet.pref <<EOF
Package: puppet puppet-common puppetmaster puppetmaster-common
Pin: version 2.7*
Pin-Priority: 501
EOF
echo Release pinned.
@garthk
garthk / fails-ask-for-resources-with-POST.out
Created October 9, 2012 23:22
Trying to get information out of puppetdb directly (puppetdb 0.9)
$ curl -vH "Accept: application/json" 'http://localhost:8080/resources' --data-urlencode 'query=["not", ["=", "type", "Nonsense"]]'
* About to connect() to localhost port 8080 (#0)
* Trying ::1... Connection refused
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /resources HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
> Host: localhost:8080
> Accept: application/json
> Content-Length: 78
@garthk
garthk / cleanupdates.cmd
Created October 22, 2012 05:20
Clean up stale Windows Update downloads
@echo on
setlocal
set DAYS=31
set DOWNLOADS=C:\WINDOWS\SoftwareDistribution\Download
rem http://bit.ly/IttCwo
rem http://stackoverflow.com/a/51069/5700
net stop wuauserv
forfiles /p %DOWNLOADS% /s /d -%DAYS% /c "cmd /c if @isdir==FALSE (del @file) else (rd /s /q @file)"
net start wuauserv
@garthk
garthk / logposts.js
Created November 27, 2012 04:31
log HTTP POSTs
var http = require('http'),
util = require('util'),
MemoryStream = require('memorystream'),
argv = require('optimist')
.usage('Usage: $0 [-a addr] [-p port]')
.options('a', { alias: 'addr', default: '0.0.0.0' })
.options('p', { alias: 'port', default: 1337 })
.options('h', { alias: 'help' })
.check(function(args) { if (args.h !== undefined) { throw ""; }})
.argv;
@garthk
garthk / console.log
Last active December 11, 2015 14:48
Trouble testing modules with Puppet 3.0 under Vagrant
root@lsserver:/tmp/vagrant-puppet/manifests# puppet --version
2.7.19
root@lsserver:/tmp/vagrant-puppet/manifests# which puppet
/usr/bin/puppet
root@lsserver:/tmp/vagrant-puppet/manifests# `which puppet` --version
3.0.2
root@lsserver:/tmp/vagrant-puppet/manifests# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/vagrant_ruby/bin:/opt/vagrant_ruby/bin
root@lsserver:/tmp/vagrant-puppet/manifests# alias
alias egrep='egrep --color=auto'
@garthk
garthk / dashboard-workers
Last active December 11, 2015 23:58
`init.d` script for Puppet Dashboard worker processes.
#!/bin/sh
### BEGIN INIT INFO
# Provides: dashboard-workers
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: dashboard workers
# Description: Start dashboard-workers daemon placed in /etc/init.d.
### END INIT INFO
@garthk
garthk / Vagrantfile
Last active December 12, 2015 01:08
Vagrant trick: upgrade Puppet, update apt-get, and install Puppet modules before the Puppet provisioner runs.
MANIFESTS = [
'vagrant-prereq.pp', # prerequisites, e.g. other Puppet modules
'vagrant.pp' # the Logstash configuration we're testing
]
# Run the Puppet provisioner for each manifest
for manifest in MANIFESTS
ls.vm.provision :puppet do |puppet|
puppet.manifests_path = "tests"
puppet.manifest_file = manifest
diff --git a/manifests/params.pp b/manifests/params.pp
index 3278a7a..06b2db5 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -89,27 +89,4 @@ class logstash::params {
for \"${::operatingsystem}\"")
}
}
-
- # parameters when using a custom jar sourcea
@garthk
garthk / elastic_template.pp
Created February 6, 2013 04:30
Puppet module to define elastic_template resource type. Doesn't ensure that the index is correct, but does ensure it's present.
define elastic_template($host='localhost', $port='9200', $prefix='', $require=undef) {
$es_templ = "${name}-template.json"
file { "/tmp/${es_templ}":
ensure => present,
source => "puppet:///modules/${module_name}/${prefix}${es_templ}",
require => $require,
}
$es_locn = "http://${host}:${port}/_template/${name}"
exec { "curl -s -XPUT ${es_locn} -d @/tmp/${es_templ}":
@garthk
garthk / fun-with-tags.pp
Created March 13, 2013 23:52
A Puppet puzzle involving gathered resources and tags.
# I was expecting this to create either /tmp/ab only, or all three files.
# Instead, it creates /tmp/a and /tmp/ab.
# What's going on?
define x() {
file { "/tmp/${name}": ensure => present }
}
@x { 'a': tag => ['a'] }
@x { 'b': tag => ['b'] }