rpm -Uvh http://rbel.frameos.org/rbel6
yum -y install rubygem-chef-server
service iptables stop
setup-chef-server.sh
knife configure -i
curl -L http://www.opscode.com/chef/install.sh | bash
In Chef, Resources represent a piece of system state and Providers are the underlying implementation which brings them into that state.
-
The compilation phase The client examines each Recipe in order and adds its Resources to the ResourceCollection
-
The execution phase The client iterates over the ResourceCollection, and performs the following:
-
Based on the Resource's "provider" attribute, a new instance of the specified Provider is created (if the attribute is not set, one is selected based on the local platform). The originating Resource is stored in the new Provider as the
@new_resource
instance variable and is accessible when writing LWPs asnew_resource.name
, for example. -
The
load_current_resource
method is then called on the provider instance, giving it an opportunity to populate@current_resource
with a new resource that represents the current state of the relevant part of the system. -
For each action specified in
@new_resource.actions
, theaction_
method that corresponds to each action is called(e.g.action :create will
invoke theaction_create
method of the Provider instance.)
Server doesn't support resource history, skipping resource report.
- Libraries
- Providers
- Resources
- Attributes
- Definitions
- Recipes
The order is important because of where you can put things, and when things are available.
This is how platform specific providers are chosen like apt/yum, useradd, etc. It also contains logic to get the provider for the resource...
- Specifically named parameter
- Platform assigned providers
- Matching the resource name
Specifically named providers are like we saw earlier where the resource itself had the provider parameter. Platform assigned are the ones like apt/yum for packages. Matching the resource name is how LWRPs get chosen.
Definetions allow you to create new Resources by stringing together existing resources.
git clone https://github.com/rcbops/chef-cookbooks.git
cd chef-cookbooks
git checkout sprint
git submodule update --init
knife cookbook bulk delete .*
knife role bulk delete .*
vi /etc/sysconfig/chef-server
OPTIONS="-h 127.0.0.1"
ignore_failure => If true, we will continue running the Recipese if this resource fails for any reason. (defaults to false)
provider => The class name of a provider to use for this resource.
retries => Number of times to cantch exceptions and retry the resource (defaults to 0). Requires Chef >= 0.10.4.
retry_delay => Retry delay in seconds (defaults to 2). Requires Chef >= 0.10.4.
supports => A hash of options that hint providers as to the capabilities of this resource.
gem_package "syntax" do
action :install
ignore_failure true
end
ruby_block "check_internet" do
block do
require 'socket'
test_host = "www.google.com"
test_port = "www"
retries = 0
begin
s = TCPSocket.new(test_host, test_port)
s.close
rescue Errno::ETIMEDOUT
if retries < 3
retries += 1
Chef::Log.logger.send("warn", "Unable to connect to #{test_host}:#{test_port}, retry ##{retries}")
retry
end
end
end
end