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@trusty-ranjib:~/workspace/chef [lxc] $ bxk bootstrap 10.0.3.39 -x ubuntu -P ubuntu --sudo
WARNING: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
WARNING: Specifying the encrypted data bag secret key using an 'encrypted_data_bag_secret'
entry in 'knife.rb' is deprecated. Please see CHEF-4011 for more details. You
can supress this warning and still distribute the secret key to all bootstrapped
machines by adding the following to your 'knife.rb' file:
knife[:secret_file] = "/path/to/your/secret"
If you would like to selectively distribute a secret key during bootstrap
class MyRecipe
end
module Extension
def foo
end
end
r1 = MyRecipe.new
r2 = MyRecipe.new
# process based .. has memory implication
sleep_time = 10
pids= []
10.times do |n|
pids << fork do
sleep sleep_time

To use a knife plugin programmatically, from any ruby script, you need first know the source of the plugin. you have to know the config options for all the command line arguments you are interested to use. All knife plugin use mixlib-cli interface, and the command line options can be found at the beginning of the file (convention), declared using option method. if you are curious take a look at mixlib-cli readme

1.require the corresponding plugin file

require '/path/to/plugin'
# stage 0 build your chef gears
require 'chef'
def run_chef(client, item)
client.node.run_list.reset!
client.node.run_list << item
run_context = Chef::RunContext.new(client.node, {}, client.events)
runner = Chef::Runner.new(run_context)
runner.converge
end
@ranjib
ranjib / dynamic_haporxy.rb
Created June 25, 2014 20:35
Dynamic haproxy using chef based on unprivileged containers (exposing containers port 80)
template '/etc/haproxy/haproxy.cfg' do
extend Helper
variables(
containers: container_ips('goatos'),
start_port: 8000
)
source 'haproxy.cfg.erb'
end
require 'blender/chef'
init(:ssh, user: 'some', password: ask('Pass: '), stdout: $stdout)
init(:chef, config_file: 'knife.rb')
members search(:chef, '*:*')
ssh_task 'run chef' do
execute 'sudo chef-client --no-fork'
end
@ranjib
ranjib / prostgres.conf.erb
Created August 20, 2014 21:35
LXC chef server tweak
listen_addresses = '<%= node['chef_server']['postgresql']['listen_address'] %>' # what IP address(es) to listen on;
port = <%= node['chef_server']['postgresql']['port'] %> # (change requires restart)
checkpoint_segments = <%= node['chef_server']['postgresql']['checkpoint_segments'] %> # in logfile segments, min 1, 16MB each, default 3
checkpoint_timeout = <%= node['chef_server']['postgresql']['checkpoint_timeout'] %> # range 30s-1h, default 5min
checkpoint_completion_target = <%= node['chef_server']['postgresql']['checkpoint_completion_target'] %> # checkpoint target duration, 0.0 - 1.0, default 0.5
checkpoint_warning = <%= node['chef_server']['postgresql']['checkpoint_warning'] %> # 0 disables, default 30s
datestyle = 'iso, mdy'
lc_messages = 'C' # locale for system error message
lc_monetary = 'C' # locale for monetary formatting
lc_numeric = 'C' # locale for number formatting
@ranjib
ranjib / test.sh
Last active August 29, 2015 14:06
GoatOS
#!/bin/bash
clean () {
rm -f etc/* keys/*;
}
start_vm(){
VM=$1
SNAPSHOT=$2
VBoxManage list runningvms | grep "$VM"
$? || VBoxManage controlvm "$VM" poweroff
@ranjib
ranjib / recipe_spec.rb
Created September 18, 2014 17:11
Common Stubs
describe 'recipe[doit]' do
before(:each) do
stub_r3dparty_cookbooks
end
it 'some awesome specs do here' do
# assertion
end
end