blender-chef Knife Plugin
Blender chef provides blender and chef integration. It enabled blender to do host discovery based on Chef searches. It also provides `knife blend` plugin that allows running a local recipe against a set of remote servers.
Install & Usage Instructions
Blender-Chef
A chef based host discovery plugin for Blender
Installation
gem install blender-chef
Usage
With blender-chef, host list for blender
jobs can be automatically
fetched from Chef server. Following is an example of dynamically obtaining
all servers with db
role, and enlisting their iptables
rule.
require 'blender/chef' config(:chef, chef_sever_url: 'https://foo.bar.com', node_name: 'admin', client_key: 'admin.pem') members(search(:chef, 'roles:db')) ssh_task 'sudo iptables -L'
Aany valid chef search can be used. You can pass the node_name
, chef_server_url
and client_key
for chef server config.
ruby
config(:chef, node_name: 'admin', client_key: 'admin.pem', chef_server_url: 'https://example.com')
members(search(:chef, 'ec2_local_ipv4:10.13.12.11'))
ssh_task 'sudo iptables -L'
Alternatively, you can also use a config file lile client.rb
or knife.rb
ruby
config(:chef, config_file: '/etc/chef/client.rb')
members(search(:chef, 'roles:db'))
By default blender-chef
will pass the FQDN of chef nodes as member list,
in this case as ssh targets. This can be customized by passing the attribute
option.
config(:chef, node_name: 'admin', client_key: 'admin.pem') members(search(:chef, 'roles:db', attribute: 'ec2_public_ipv4'))
Knife integration
Blender-chef comes with a knife plugin that allows job or chef recipe
execution from CLI.
- Running raw blender jobs
Given the following job present in file
jobs/upgrade_chef.rb
ssh_task 'sudo apt-get remove chef --purge' ssh_task 'sudo apt-get remove chef --purge' ssh_task 'wget -c https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/13.04/x86_64/chef_12.0.3-1_amd64.deb' ssh_task 'sudo dpkg -i chef_12.0.3-1_amd64.deb' ssh_task 'sudo chef-client'
It can be executed against all chef nodes having db
role as:
knife blend --search 'roles:db' jobs/upgrade_chef.rb
- Running local one-off chef recipes against remote nodes using blender
Given the following chef recipe present ina local file
recipes/nginx.rb
package 'nginx' service 'nginx' do action [:start, :enable] end
It can be executed against all chef nodes having web
role as:
knife blend --recipe-mode --search 'roles:web' recipes/nginx.rb
In --recipe-mode
blender will treat the input file(s) as chef recipe
and build necessary scp and ssh tasks to upload the recipe, execute it
and remove the uploaded recipe.
Additional options are provided to control strategy, ssh credentials etc.