Skip to content

Commit

Permalink
Merge branch 'COOK-466'
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimberman committed Feb 18, 2011
2 parents 9a5f8ed + 863c4b6 commit 43e1d64
Show file tree
Hide file tree
Showing 34 changed files with 1,321 additions and 40 deletions.
25 changes: 6 additions & 19 deletions apt/README.md
Expand Up @@ -8,20 +8,17 @@ Recipes

default
-------

The default recipe runs apt-get update during the Compile Phase of the Chef run to ensure that the system's package cache is updated with the latest. It is recommended that this recipe appear first in a node's run list (directly or through a role) to ensure that when installing packages, Chef will be able to download the latest version available on the remote APT repository.

This recipe also sets up a local cache directory for preseeding packages.

cacher
------
Installs the apt-cacher package and service so the system can provide APT caching. You can check the usage report at http://{hostname}:3142/report. The cacher recipe includes the `cacher-client` recipe, so it helps seed itself.

Installs the apt-cacher package and service so the system can be an APT cache.

proxy
-----

Installs the apt-proxy package and service so the system can be an APT proxy.
cacher-client
-------------
Configures the node to use the apt-cacher server as a client.

Resources/Providers
===================
Expand All @@ -42,6 +39,8 @@ Put `recipe[apt]` first in the run list. If you have other recipes that you want

The above will run during execution phase since it is a normal template resource, and should appear before other package resources that need the sources in the template.

Put `recipe[apt::cacher]` in the run_list for a server to provide APT caching and add `recipe[apt::cacher-client]` on the rest of the Debian-based nodes to take advantage of the caching server.

An example of The LWRP `apt_repository` `add` action:

apt_repository "zenoss" do
Expand All @@ -51,18 +50,6 @@ An example of The LWRP `apt_repository` `add` action:
action :add
end

An example of `apt_repository` using a signing key:

apt_repository "hardy-rsyslog-ppa" do
uri "http://ppa.launchpad.net/a.bono/rsyslog/ubuntu"
distribution "hardy"
components ["main"]
keyserver "keyserver.ubuntu.com"
key "C0061A4A"
action :add
notifies :run, "execute[apt-get update]", :immediately
end

and the `remove` action:

apt_repository "zenoss" do
Expand Down
4 changes: 2 additions & 2 deletions apt/metadata.rb
Expand Up @@ -3,10 +3,10 @@
license "Apache 2.0"
description "Configures apt and apt services and an LWRP for managing apt repositories"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "1.0.0"
version "1.1.0"
recipe "apt", "Runs apt-get update during compile phase and sets up preseed directories"
recipe "apt::cacher", "Set up an APT cache"
recipe "apt::proxy", "Set up an APT proxy"
recipe "apt::cacher-client", "Client for the apt::cacher server"

%w{ ubuntu debian }.each do |os|
supports os
Expand Down
37 changes: 37 additions & 0 deletions apt/recipes/cacher-client.rb
@@ -0,0 +1,37 @@
#
# Cookbook Name:: apt
# Recipe:: cacher-client
#
# Copyright 2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

servers = search(:node, 'recipes:apt\:\:cacher') || []
if servers.length > 0
Chef::Log.info("apt-cacher server found on #{servers[0]}.")
proxy = "Acquire::http::Proxy \"http://#{servers[0].ipaddress}:3142\";"
file "/etc/apt/apt.conf.d/01proxy" do
owner "root"
group "root"
mode "0644"
content proxy
action :create
end
else
Chef::Log.info("No apt-cacher server found.")
file "/etc/apt/apt.conf.d/01proxy" do
action :delete
only_if {File.exists?("/etc/apt/apt.conf.d/01proxy")}
end
end
5 changes: 4 additions & 1 deletion apt/recipes/cacher.rb
Expand Up @@ -2,7 +2,7 @@
# Cookbook Name:: apt
# Recipe:: cacher
#
# Copyright 2008-2009, Opscode, Inc.
# Copyright 2008-2011, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,3 +40,6 @@
mode 0644
notifies :restart, resources(:service => "apt-cacher")
end

#this will help seed the proxy
include_recipe "apt::cacher-client"
71 changes: 71 additions & 0 deletions one-shot/README.md
@@ -0,0 +1,71 @@
Description
===========
This cookbook provides a framework for making single-use, one-shot recipes. By including the `one-shot` recipe in the node's run_list, on the next chef-client run the contents of the `one-shot::one-shot` recipe will be called. This is parameterized as an attribute, so you can change these out by setting the `["one_shot"]["recipe"]` to include different recipes. The file `roles/one-shot.rb` is included so you can simply change the role instead of changing the source directly.

Requirements
============
Written with Chef 0.9.12.

Testing
-------
Tested on Ubuntu 10.04 and 10.10 and tested with Chef 0.9.12.

Attributes
==========
The attribute is set in `attributes/default.rb` and can be set via the `roles/one-shot.rb` Role as well (or you could edit the `default.rb` recipe directly).

* `["one_shot"]["recipe"]` - Default is `one-shot::one-shot`, but may be set to alternate recipes so you may have multiple recipes to use, depending on this attribute.

Roles
=====
one-shot
--------
This role is provided by the `roles/one-shot.rb` for setting the `["one_shot"]["recipe"]` attribute.

knife role from file cookbooks/one-shot/roles/one-shot.rb
knife node run_list add YOURNODE 'role[one-shot]'


Recipes
=======
Default
-------
The default recipe includes the recipe referred to by the `["one_shot"]["recipe"]` attribute, executing it and then removing the `oneshot` recipe from the node's run_list.

One-Shot
--------
This is an example implementation of a one-shot recipe, it may be copied or modified as necessary. Access to additional recipes are made through the `["one_shot"]["recipe"]` attribute. This recipe is accessed by the `attributes/default.rb`.

Two-Shot
--------
This is an example implementation of a one-shot recipe, it may be copied or modified as necessary. Access to additional recipes are made through the `["one_shot"]["recipe"]` attribute. This recipe is accessed by the `roles/one-shot.rb` Role.

Usage
=====
Add the `one-shot` recipe to a node's run_list. Next chef-client run, that node will execute the recipe designated by the `["one_shot"]["recipe"]` attribute, then remove itself from the node's run_list. The attribute may be set with a Role or directly in the source of the cookbook. You can update the `one-shot` Role with any changes for future runs, then add the `one-shot` recipe back to the run_list again. It could definitely be used within another Role and applied to a series of nodes if needed.

knife node run_list add YOURNODE 'recipe[one-shot]'

optional

knife role from file cookbooks/one-shot/roles/one-shot.rb
knife node run_list add YOURNODE 'role[one-shot]'


License and Author
==================
Author:: Matt Ray <matt@opscode.com>

Copyright:: 2011 Opscode, Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
24 changes: 6 additions & 18 deletions apt/recipes/proxy.rb → one-shot/attributes/default.rb
@@ -1,8 +1,9 @@
#
# Cookbook Name:: apt
# Recipe:: proxy
# Author:: Matt Ray <matt@opscode.com>
# Cookbook Name:: zenoss
# Attributes:: default
#
# Copyright 2008-2009, Opscode, Inc.
# Copyright 2011 Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,19 +17,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
package "apt-proxy" do
action :install
end

service "apt-proxy" do
supports :restart => true, :status => false
action [ :enable, :start ]
end

cookbook_file "/etc/apt-proxy/apt-proxy-v2.conf" do
source "apt-proxy-v2.conf"
owner "root"
group "root"
mode 0644
notifies :restart, resources(:service => "apt-proxy")
end
#additional one-shots can be added by changing the name of the recipe
default[:one_shot][:recipe] = "one-shot::one-shot"
31 changes: 31 additions & 0 deletions one-shot/metadata.json
@@ -0,0 +1,31 @@
{
"long_description": "",
"recipes": {
"one-shot::one-shot": "The recipe to be executed a single time.",
"default": "Includes the `one-shot` recipe and removes itself from the run_list."
},
"attributes": {
},
"providing": {
},
"dependencies": {
},
"maintainer": "Opscode, Inc.",
"replacing": {
},
"maintainer_email": "matt@opscode.com",
"groupings": {
},
"platforms": {
},
"license": "Apache 2.0",
"version": "0.1.0",
"recommendations": {
},
"suggestions": {
},
"name": "one-shot",
"description": "Runs the contents of the one-shot.rb and removes it from the run_list",
"conflicting": {
}
}
7 changes: 7 additions & 0 deletions one-shot/metadata.rb
@@ -0,0 +1,7 @@
maintainer "Opscode, Inc."
maintainer_email "matt@opscode.com"
license "Apache 2.0"
description "Runs the contents of the one-shot.rb and removes it from the run_list"
version "0.1"
recipe "one-shot::one-shot", "The recipe to be executed a single time."
recipe "default", "Includes the `one-shot` recipe and removes itself from the run_list."
31 changes: 31 additions & 0 deletions one-shot/recipes/default.rb
@@ -0,0 +1,31 @@
#
# Author:: Matt Ray <matt@opscode.com>
# Cookbook Name:: one-shot
# Recipe:: default
#
# Copyright 2011, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

oneshot = node["one_shot"]["recipe"]

include_recipe oneshot

ruby_block "remove one-shot recipe #{oneshot}" do
block do
Chef::Log.info("One-Shot recipe #{oneshot} executed and removed from run_list")
node.run_list.remove("recipe[one-shot]") if node.run_list.include?("recipe[one-shot]")
end
action :create
end
21 changes: 21 additions & 0 deletions one-shot/recipes/one-shot.rb
@@ -0,0 +1,21 @@
#
# Author:: Matt Ray <matt@opscode.com>
# Cookbook Name:: one-shot
# Recipe:: one-shot
#
# Copyright 2011, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

Chef::Log.info("one-shot::one-shot called and executed!")
21 changes: 21 additions & 0 deletions one-shot/recipes/two-shot.rb
@@ -0,0 +1,21 @@
#
# Author:: Matt Ray <matt@opscode.com>
# Cookbook Name:: one-shot
# Recipe:: two-shot
#
# Copyright 2011, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

Chef::Log.info("one-shot::two-shot called and executed!")
7 changes: 7 additions & 0 deletions one-shot/roles/one-shot.rb
@@ -0,0 +1,7 @@
name "one-shot"
description "One-Shot attribute for selecting recipe"
override_attributes(
"one_shot" => {
"recipe" => "one-shot::two-shot"
}
)

0 comments on commit 43e1d64

Please sign in to comment.