Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

The crazytown cookbook has been deprecated

The crazytown cookbook has been deprecated and is no longer being maintained by its authors. Use of the crazytown cookbook is no longer recommended. You may find that the resource cookbook is a suitable alternative.

RSS

crazytown (2) Versions 0.1.1

Easier, more powerful Chef Resources

Berkshelf/Librarian
Policyfile
Knife
cookbook 'crazytown', '~> 0.1.1'
cookbook 'crazytown', '~> 0.1.1', :supermarket
knife cookbook site install crazytown
knife cookbook site download crazytown
README
Dependencies
Quality 11%

Crazytown

Chef Resources are incredibly important to creating good, useful, reusable cookbooks. Yet people often don't create them because it's too hard. Crazytown aims to change that.

Crazytown is an attempt to make Chef Resources significantly easier and more fun to create, while being even more powerful. It does this by:

  • Vastly simplifying resource writing so you just make a "resource" and "recipe" in a single file.
  • Allowing users to read data from resources, making them significantly more useful.
  • Allowing users to easily customize resource definitions in-place, adding defaults and tweaks.

I am looking for people to try this out and give feedback. IT IS EXPERIMENTAL. There are bugs (though I generally don't know what they are). Things will change. There is a lot of feedback to gather and that will affect what it does. But this has been revised many, many times in an attempt to produce something close enough to right that I hope it won't change much, or in fundamental ways.

This is also unfinished in that there are more features to be added: chief among them are nested properties (Hash, Array, Set and Struct), nested resources (github.organization.repository) and recipe semantics (immediate mode and parallel recipes). 0.1 is a stop along the way, but a very significant one that defines the basis for Resources.

To give feedback, file issues in github or chat on Gitter. More documentation can be found in the Crazytown README

Getting Started

To get started, upload the crazytown cookbook and add this to your metadata.rb:

depends "crazytown"

Crazytown is now loaded in, and the following features are available to all: - Crazytown.resource, Crazytown.define and Crazytown.defaults - All recipes can call Crazytown resources

You will now have all Crazytown features available to your cookbook: - The resources directory now creates Crazytown resources (via Crazytown.resource). - Recipes in your cookbook have resource, define and defaults available (which call the Crazytown. equivalent)

NOTE: cookbooks that depend on your cookbook will not automatically be Crazytowned. Only cookbooks that explicitly depend on crazytown will be transformed.

Compatibility

Crazytown works with Chef 12. It also does not change anything about existing cookbook behavior, and only affects cookbooks who have depends "crazytown" in their metadata. The one exception is that resources you create with Crazytown are available to all cookbooks.

Define: Dashing Off a Quick Resource

Say you noticed that you're creating a series of "user home directories," like this:

# Old recipe
user 'jkeiser' do
  group 'users'
end

directory "/home/jkeiser" do
  owner 'jkeiser'
  group 'users'
  mode 0700
end

file "/home/jkeiser/.bashrc" do
  owner 'jkeiser'
  group 'users'
  mode 0700
  content "sh /sys/global_bashrc"
end

user 'fnichol' do
  group 'users'
end

directory "/home/fnichol" do
  owner 'fnichol'
  group 'users'
  mode 0700
end

file "/home/fnichol/.bashrc" do
  owner 'fnichol'
  group 'users'
  mode 0700
  content "sh /sys/global_bashrc"
end

...

That's a lot of repetition! How do you make repetition better in Chef? A resource! Just write this in your recipe:

define :user_bundle, :username, primary_group: 'users' do
  user username do
    group primary_group
  end

  directory "/home/#{username}" do
    owner username
    group primary_group
    mode 0700
  end

  file "/home/#{username}/.bashrc" do
    content "sh /sys/global_bashrc"

    owner username
    group primary_group
    mode 0700
  end
end

# Now let's use our resource!
user_bundle 'jkeiser' do
end
user_bundle 'fnichol' do
end
user_bundle 'blargh' do
end

Much more concise, much more readable, much easier to change!

Creating a Simple Resource

If you want to really customize the properties of a resource, or want to do more interesting things, you can always create a resources file. Crazytown appropriates the LWRP resources directory, so you create a resources/user_bundle.rb:

# resources/user_bundle.rb
property :username, String, identity: true
property :primary_group, String
property :home_dir, Path, relative_to: '/home' do
  default { username }
end

recipe do
  user username do
    group primary_group
  end

  directory home_dir do
    owner username
    group primary_group
    mode 0700
  end

  file "#{home_dir}/.bashrc" do
    content "sh /sys/global_bashrc"

    owner username
    group primary_group
    mode 0700
  end
end
# recipes/default.rb
test_user_bundle 'jkeiser' do
end
test_user_bundle 'fnichol' do
end
test_user_bundle 'blargh' do
end

Some features here: - property is how you define a named thing - identity: true means that when you write user_bundle 'jkeiser', username will be set to jkeiser. - String and Path are property types. It means the resource will not allow the user to set the property to something else, like 1 or false, which isn't a valid path or username. - relative_to: '/home' is a modifier for Path saying "when the user says home_dir 'jkeiser2', set home_dir to /home/jkeiser2." - default { username } is a computed default: if the user does not set home_dir, home_dir will be /home/<username>

NOTE: you can define a resource anywhere by writing Crazytown.resource :name do ... end, and writing property and recipe statements inside. You can do this in libraries, recipes or even outside Chef.

Building Primitive Resources: Load and Converge

Up until now, we've been showing "compound" resources whose primary job is to wrap other resources like file, package and service. This is enough for huge numbers of people, and the primitive resources handle the work of "test-and-set," showing the "(up to date)" if nothing needs to change, or the green text when a change occurs.

Sometimes you need to build a real primitive resource, when file package and service aren't enough. When this comes up, Crazytown handles the work of test-and-set for you with the load and converge methods.

Consider a simple file resource:

# resources/file.rb
property :path, Path, identity: true
property :mode, Integer
property :content, String

recipe do
  converge do
    File.chmod(mode, path)
    IO.write(path, content)
  end
end

def load
  mode File.stat(path).mode
  content IO.read(path)
end

The new things here:

  • converge do ... handles test-and-set. It will check to see if the user has changed mode or content from its real value (as read in by load). If so, it will print an appropriate message in green text showing what's changed, and mark the resource as updated.
  • def load loads the current values of the actual resource. This is called when converge happens, or when the user asks for a value that hasn't been filled in (like if they ask for mode and haven't set it yet).

What's also interesting is you have now defined a read API. If the user does file('/x.txt').content, then it will show you the file contents of /x.txt.

Customizing Resources in Cookbooks: Defaults

As a user of a resource, there are a number of times where you're repeating something over and over. How many of us have typed this:

file '/x.txt' do
  owner 'jkeiser'
  group 'users'
  mode 0755
  content 'x'
end
file '/y.txt' do
  owner 'jkeiser'
  group 'users'
  mode 0755
  content 'y'
end
file '/z.txt' do
  owner 'jkeiser'
  group 'users'
  mode 0755
  content 'z'
end

Crazytown gives you a quick way to redefine the defaults of a resource:

defaults :my_file, :file, owner: 'jkeiser', group: 'users', mode: 0755
my_file '/x.txt' do
  content 'x'
end
my_file '/y.txt' do
  content 'y'
end
my_file '/z.txt' do
  content 'z'
end

You can also specialize resources with more complex behavior:

# A version of "file" that assumes the group == the username
resource :my_file, :file do
  attribute :group, String do
    default { username }
  end
end

Dependent cookbooks

This cookbook has no specified dependencies.

Contingent cookbooks

There are no cookbooks that are contingent upon this one.

Collaborator Number Metric
            

0.1.1 failed this metric

Failure: Cookbook has 0 collaborators. A cookbook must have at least 2 collaborators to pass this metric.

Contributing File Metric
            

0.1.1 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a CONTRIBUTING.md file

Foodcritic Metric
            

0.1.1 failed this metric

FC055: Ensure maintainer is set in metadata: crazytown/metadata.rb:1
FC056: Ensure maintainer_email is set in metadata: crazytown/metadata.rb:1
FC064: Ensure issues_url is set in metadata: crazytown/metadata.rb:1
FC065: Ensure source_url is set in metadata: crazytown/metadata.rb:1
FC066: Ensure chef_version is set in metadata: crazytown/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: crazytown/metadata.rb:1
FC068: Ensure license is set in metadata: crazytown/metadata.rb:1
FC069: Ensure standardized license defined in metadata: crazytown/metadata.rb:1
Run with Foodcritic Version 12.2.1 with tags metadata,correctness ~FC031 ~FC045 and failure tags any

License Metric
            

0.1.1 failed this metric

crazytown does not have a valid open source license.
Acceptable licenses include Apache-2.0, apachev2, Apache 2.0, MIT, mit, GPL-2.0, gplv2, GNU Public License 2.0, GPL-3.0, gplv3, GNU Public License 3.0.

No Binaries Metric
            

0.1.1 passed this metric

Publish Metric
            

0.1.1 failed this metric

crazytown is deprecated

Supported Platforms Metric
            

0.1.1 failed this metric

crazytown should declare what platform(s) it supports.

Testing File Metric
            

0.1.1 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file

Version Tag Metric
            

0.1.1 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number