Skip to content

Instantly share code, notes, and snippets.

View jtimberman's full-sized avatar
🚀

Joshua Timberman jtimberman

🚀
View GitHub Profile
@jtimberman
jtimberman / ec2_client.rb
Created March 2, 2010 03:38
generate user_data.json with knife, launch instance with it and magic!
# Author:: Adam Jacob <adam@opscode.com>
# Author:: Joshua Timberman <joshua@opscode.com>
#
# Copyright 2009-2010, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@jtimberman
jtimberman / knife.rb
Created October 3, 2011 21:24
First stab at a knife.rb with comments for all the various knife plugins we publish
log_level :info
log_location STDOUT
node_name ENV['USER']
client_key "#{ENV['HOME']}/.chef/#{ENV['USER']}.pem"
validation_client_name 'chef-validator'
validation_key '/etc/chef/validation.pem'
chef_server_url 'http://localhost:4000'
cache_type 'BasicFile'
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
cookbook_path [ '/var/chef/cookbooks' ]
@jtimberman
jtimberman / default_spec.rb
Created May 10, 2013 03:14
this is cookbooks/java/spec/default_spec.rb. Then install the chefspec gem and run rspec. (yay!)
require 'chefspec'
describe 'java::default' do
let (:chef_run) { ChefSpec::ChefRunner.new.converge('java::default') }
it 'should include the openjdk recipe by default' do
chef_run.should include_recipe 'java::openjdk'
end
context 'windows' do
let(:chef_run) do
@jtimberman
jtimberman / fun-with-knife-and-jq.md
Created May 8, 2020 21:32
Reminder that Chef has an rich set of data and an API

Did you know that every time the chef-client runs, it knows what time it is, and it stores that value as a node attribute, ohai_time? Did you know that you can use this value for searching a Chef Infra Server? It's a Unix Epoch!

For example, let's look for the nodes that were updated in the last 10-15 minutes:

now=$(date +%s)
range_start=$(expr $now - 900)
range_end=$(expr $now - 600)

knife search node "ohai_time:[$range_start TO $range_end]" -a ohai_time -F json

Prerequisites

You'll need to have a system running that is accessible through a DNS record. It should have access to the public Habitat depot, https://app.habitat.sh so it can download the required packages.

You'll need to register an OAuth application for GitHub. You need the client ID and client secret that are created for the application later in this guide. Your system needs to have access to https://github.com so that it can authenticate.

Your system also needs to have an FQDN that can be resolved, for example depot.example.com. This will be used in your OAuth application's "Authorization Callback URL." For this example, use http://depot.example.com/#/sign-in. The /#/sign-in is required.

Operating System

@jtimberman
jtimberman / cbfrozen.rb
Last active February 5, 2020 18:31
displays whether cookbooks are frozen on the chef server for a given version. put this in ~/.chef/plugins/knife.
#
# Author: Joshua Timberman <joshua@opscode.com>
# Copyright (c) 2013, Opscode, Inc <legal@opscode.com>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@jtimberman
jtimberman / gist:1040853
Created June 22, 2011 19:07
Ohai plugin to return semantic reference attributes for network addresses
# This might not work on newer (than 0.10.6) versions of Chef.
# Thanks for pointing to my new gist, spkane :)
# https://gist.github.com/1040543
require 'rubygems'
require 'ohai'
o = Ohai::System.new()
o.all_plugins
@jtimberman
jtimberman / about.md
Last active January 11, 2020 22:54
This is the role I use on my "Linux Workstation" systems. I don't have a desktop Linux system, but I do have a couple that I ssh to for work/development purposes especially when traveling.

Most of the recipes are just from the Opscode cookbooks. Exceptions or differences:

  • ruby19 is a recipe that just installs ruby1.9.1-full, nothing fancy. Use Fletcher Nichol's rbenv or rvm cookbooks for those if you prefer.
  • emacs24 recipe is one that I used to install Emacs 24 from a PPA before it was officially released. The actual recipe is attached to this gist, just put it in a cookbook named emacs24 as the default recipe.
  • users recipe is one that just manages the dotfiles for my user, it's based on a really old version of Opscode's users cookbook.

Keybase proof

I hereby claim:

  • I am jtimberman on github.
  • I am jtimberman (https://keybase.io/jtimberman) on keybase.
  • I have a public key ASCJzdFw_o9eVy7biR2J5moJQ_AmV1Mcj2V-vUIITlkiVAo

To claim this, I am signing this object:

@jtimberman
jtimberman / nginx.conf
Created March 5, 2010 21:01 — forked from johnthethird/nginx.conf
nginx front end for Riak
# Config for Nginx to act as a front-end for Riak
# The main goal is to proxy all GETs directly to Riak, and disallow anything else (POST, PUT, etc)
# Also, disallow use of the map/reduce query links (i.e. /riak/bucket/key/_,_,_)
# Config is in /etc/nginx/sites-available/default or somewhere like that
# Set up load-balancing to send requests to all nodes in the Riak cluster
# Replace these IPs/ports with the locations of your Riak nodes
upstream riak_hosts {
server 127.0.0.1:8098;