Skip to content

Instantly share code, notes, and snippets.

View nicklewis's full-sized avatar

Nick Lewis nicklewis

View GitHub Profile
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb
index fc36c35..be04a90 100644
--- a/lib/puppet/node/environment.rb
+++ b/lib/puppet/node/environment.rb
@@ -57,6 +57,7 @@ class Puppet::Node::Environment
def self.clear
@seen.clear
+ self.current = nil
end
@nicklewis
nicklewis / gist:2402713
Created April 17, 2012 01:13
weird array vs. string append behavior
$topscope_array = ['a']
$topscope_string = 'a'
node default {
$array = ['a']
$string = 'a'
include foo
notify { "node array is $array (should be a)": }
notify { "node string is $string (should be a)": }
}
{
"command": "deactivate node",
"payload": "\"the_node_name\"",
"version": 1
}
@nicklewis
nicklewis / dfa.pp
Last active October 8, 2015 08:48
A DFA in Puppet language
class print_result($result,$input){
$answer = $result ? {
s1 => even,
s2 => odd,
}
notify { "The input $input is $answer": }
}
define dfa($state,$original_input,$input,$rules,$callback) {
$first = inline_template("<%= input[0] %>")
@nicklewis
nicklewis / gist:6300156
Last active December 21, 2015 11:38
puppetdb metric
curl -H 'Accept: application/json' http://<puppetdb>:8080/v2/metrics/mbean/com.puppetlabs.puppetdb.command%3Atype%3Dglobal%2Cname%3Dprocessing-time
/v2/metrics/mbean/com.puppetlabs.puppetdb.scf.storage%3Atype%3Ddefault%2Cname%3Dgc-catalogs-time
/v2/metrics/mbean/com.puppetlabs.puppetdb.scf.storage%3Atype%3Ddefault%2Cname%3Dgc-params-time
/v2/metrics/mbean/com.puppetlabs.puppetdb.scf.storage%3Atype%3Ddefault%2Cname%3Dreplace-catalog-time
@nicklewis
nicklewis / gist:6384464
Created August 29, 2013 23:01
Hypothetical PuppetDB ternary operator
["and",
["=", "type", "Package"],
["?:",
["in", "certname",
["extract", "certname",
["select-facts",
["and", ["=", "name", "kernelrelease"], ["=", "value", "3.2.0-3-amd64"]]]]]
["=", "title", "linux-headers-3.2.0-3-amd64"],
["=", "title", "linux-headers-3.2.0-2-amd64"]]]
@nicklewis
nicklewis / gist:6515299
Created September 10, 2013 20:37
postgres relation sizes
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_relation_size(C.oid)) AS "size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_relation_size(C.oid) DESC
LIMIT 20;
@nicklewis
nicklewis / jira_epic_graph.rb
Created January 4, 2017 23:58
Generate a dot graph of the blocking relationships between all the tickets in a set of epics
#!/usr/bin/env ruby
require 'net/http'
require 'json'
raise "Specify at least one epic" if ARGV.empty?
def make_request(client, url)
request = Net::HTTP::Get.new(url)
request.basic_auth ENV['JIRA_USERNAME'], ENV['JIRA_PASSWORD']
WITH inactive_nodes
AS (SELECT certname
FROM certnames
WHERE ( deactivated IS NOT NULL
OR expired IS NOT NULL ))
SELECT reports.certname AS certname,
Encode(reports.hash :: bytea, 'hex') AS hash,
reports.end_time AS end_time,
reports.noop AS noop,
report_statuses.status AS status,
@nicklewis
nicklewis / Dockerfile
Last active November 9, 2017 20:00
dockerfile for bolt
FROM alpine:latest
RUN apk --update add ruby ruby-json ruby-io-console openssh gcc ruby-dev make musl-dev libffi-dev curl tar
RUN gem install bolt --no-ri --no-rdoc
WORKDIR /var/lib/bolt
RUN mkdir package service
RUN curl -s https://forge.puppet.com/v3/files/puppetlabs-package-0.1.5.tar.gz | tar zxf - --strip-components=1 -C package --wildcards '*/tasks'
RUN curl -s https://forge.puppet.com/v3/files/puppetlabs-service-0.1.3.tar.gz | tar zxf - --strip-components=1 -C service --wildcards '*/tasks'