Skip to content

Instantly share code, notes, and snippets.

View ranjib's full-sized avatar
🥁
having fun

Ranjib Dey ranjib

🥁
having fun
View GitHub Profile
@ranjib
ranjib / rbenv_apply.rb
Created September 10, 2013 02:21
rbenv installation
package "build-essential"
package "curl"
package "libssl-dev"
package "git"
@ranjib
ranjib / chef_server_spec.rb
Created September 9, 2013 17:04
test chef server provisioning
require 'lxc'
require 'mixlib/shellout'
require 'lxc/extension.rb'
describe "Chef Server installation" do
let(:chef_server) do
c = LXC::Container.new('chef-server')
c.ssh_user = 'ubuntu'
@ranjib
ranjib / chef_server_apply.rb
Last active December 22, 2015 10:28
Install chef server via chef apply
remote_file '/opt/chef-server.deb' do
source 'https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chef-server_11.0.8-1.ubuntu.12.04_amd64.deb'
not_if {File.exists?('/opt/chef-server.deb')}
end
dpkg_package 'chef-server' do
source '/opt/chef-server.deb'
action :install
end
@ranjib
ranjib / README.md
Last active December 19, 2015 13:19
DataDog Based Realtime Chef monitoring

Chef 11 introduces event dispatching mechanism, which emits event at different milestones in Chef run (aka lifecycle) , and users can add their custom handlers to hook into these events. Chef formatters already uses this API. For a complete list of currently available events check this

Following is a bare minimal example for adding a custom handler:

chef_event_handler_foo.rb

require 'chef/event_dispatch/base'
class Foo < Chef::EventDispatch::Base
  # lets say hello world when chef run ends
 def run_completed(node)
@ranjib
ranjib / ChefProfile.md
Last active February 14, 2023 01:42
Chef profiling with ruby-prof

install KCacheGrind

apt-get install kcachegrind

Sandbox things

Create a sandbox folder and install Chef and rubyprof there with bundler

@ranjib
ranjib / happy_birtday.c
Created June 28, 2013 20:10
And you think system administrators are grumpy ? :-)
#include <sys/sysinfo.h>
#include <stdio.h>
int seconds2days(int seconds){
return seconds/(60*60*24);
}
int days2year(int days){
return days/365;
}
@ranjib
ranjib / chef_validator_migration.md
Last active December 18, 2015 11:59
Migrating chef-validator client

Grab the validation client in json format from old chef server

knife client show chef-validator -c knife-chef-server-10.rb -Fj > chef-validator.json

Upload the validation client to new chef server, delete the existing validation client from new chef server first, as update(PUT) is not allowed, only create(POST) is allowed

knife client delete chef-validator -y -c knife-chef-server-11.rb
@ranjib
ranjib / Chef_Internal_TOC.md
Last active December 18, 2015 04:28
Topics that we can discuss on chef internal

Topics

  1. Mixlib-shell out interface :: A portable , cross platform command execution module. How to use it with any arbitrary code, how chef interfaces with it (shellout, shellout! etc)

  2. Mixlib-Cli :: The awesome command line argument processor. How to use it with any arbitrary program , pitfalls associated with reusing classes that uses mixlib-cli

  3. A generic overview of the chef rest class (Chef::Rest) and main domain objects (Node, Role, ApiClient etc). How to access them from any arbitrary scripts (#load, #list . #search etc).

  4. Anatomy of a chef run (revisited with chef internal) :

    1. setup phase (logging setup, configuration setups, client registration, getting a node's runlist)
  5. cookbook syncing,

require 'chef'
Chef::Config.from_file('knife.rb')
envs = Chef::Environment.list.keys
q = Chef::Search::Query.new
envs.each do |e|
constrained_cookbooks = Chef::Environment.load(e).cookbook_versions.keys
all_cookbooks =[]
nodes = q.search(:node, "chef_environment:#{e}").first.reject(&:nil?)
nodes.select{|n| n.attribute?(:recipes)}.each do |n|
n.recipes.map{|r| r.split('::')[0]}.each do |cookbook|
ranjib@ranjib-pd:~/workspace/foss/community-cookbooks/apt [master] $ gem list
*** LOCAL GEMS ***
activesupport (3.2.13)
addressable (2.3.3)
archive-tar-minitar (0.5.2)
awesome_print (1.0.2)
berkshelf (1.3.1)
bigdecimal (1.1.0)