-
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)
-
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
-
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).
-
Anatomy of a chef run (revisited with chef internal) :
- setup phase (logging setup, configuration setups, client registration, getting a node's runlist)
-
cookbook syncing,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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| |
knife client show chef-validator -c knife-chef-server-10.rb -Fj > chef-validator.jsonUpload 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <sys/sysinfo.h> | |
| #include <stdio.h> | |
| int seconds2days(int seconds){ | |
| return seconds/(60*60*24); | |
| } | |
| int days2year(int days){ | |
| return days/365; | |
| } |
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:
require 'chef/event_dispatch/base'
class Foo < Chef::EventDispatch::Base
# lets say hello world when chef run ends
def run_completed(node)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package "build-essential" | |
| package "curl" | |
| package "libssl-dev" | |
| package "git" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package "build-essential" | |
| package "mercurial" | |
| package "bison" | |
| package "curl" | |
| package "git" | |
| execute "install_gvm" do | |
| user "ubuntu" | |
| cwd "/home/ubuntu" |