Reader small image

You're reading from  Chef Cookbook - Third Edition

Product typeBook
Published inFeb 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781786465351
Edition3rd Edition
Languages
Tools
Right arrow
Author (1)
Matthias Marschall
Matthias Marschall
author image
Matthias Marschall

Matthias Marschall is a Software Engineer "made in Germany". His four children make sure that he feels comfortable in lively environments, and stays in control of chaotic situations. A lean and agile engineering lead, he's passionate about continuous delivery, infrastructure automation, and all things DevOps. In recent years, Matthias has helped build several web-based businesses, first with Java and then with Ruby on Rails. He quickly grew into system administration, writing his own configuration management tool before migrating his whole infrastructure to Chef in its early days. In 2008, he started a blog (http://www.agileweboperations.com) together with Dan Ackerson. There, they have shared their ideas about DevOps since the early days of the continually emerging movement. You can find him on Twitter as @mmarschall. Matthias holds a Master's degree in Computer Science (Dipl.-Inf. (FH)) and teaches courses on Agile Software Development at the University of Augsburg. When not writing or coding, Matthias enjoys drawing cartoons and playing Go. He lives near Munich, Germany.
Read more about Matthias Marschall

Right arrow

Freezing cookbooks


Uploading broken cookbooks that override your working ones is a major pain and can result in widespread outages throughout your infrastructure. If you have a cookbook version, you tested successfully with Test Kitchen, it's a good idea to freeze this version so that no one can overwrite the same version with broken code. When used together with version constraints that are specified in your environment manifests, freezing cookbooks can keep your production servers safe from accidental changes.

Note

Berkshelf takes care of freezing cookbooks automatically.

Getting ready

Make sure you have at least one cookbook (I'll use the ntp cookbook) registered with your Chef server.

How to do it…

Let's see what happens if we freeze a cookbook.

  1. Upload a cookbook and freeze it:

    mma@laptop:~/chef-repo $ knife cookbook upload ntp --freeze
    Uploading ntp            [3.2.0]
    Uploaded 1 cookbook.
    
  2. Try to upload the same cookbook version again:

    mma@laptop:~/chef-repo $ knife cookbook upload ntp
    Uploading ntp            [3.2.0]
    ERROR: Version 3.2.0 of cookbook ntp is frozen. Use --force to override.
    WARNING: Not updating version constraints for ntp in the environment as the cookbook is frozen.
    ERROR: Failed to upload 1 cookbook.
    
  3. Change the cookbook version:

    mma@laptop:~/chef-repo $ subl cookbooks/ntp/metadata.rb
    
    version           "3.2.1"
    
  4. Upload the cookbook again:

    mma@laptop:~/chef-repo $ knife cookbook upload ntp
    Uploading ntp            [3.2.1]
    Uploaded 1 cookbook.
    

How it works…

By using the --freeze option when uploading a cookbook, you tell the Chef server that it should not accept any changes to the same version of the cookbook anymore. This is important if you're using environments and want to make sure that your production environment cannot be broken by uploading a corrupted cookbook.

By changing the version number of your cookbook, you can upload the new version. Then you can make, for example, your staging environment use that new cookbook version.

There's more…

To support a more elaborate workflow, you can use the knife-spork knife plugin, which comes pre-installed with the Chef DK. It helps multiple developers work on the same Chef server and repository without treading on each other's toes. You can find more information about it at https://docs.chef.io/plugin_knife_spork.html.

See also

Previous PageNext Page
You have been reading a chapter from
Chef Cookbook - Third Edition
Published in: Feb 2017Publisher: PacktISBN-13: 9781786465351
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Matthias Marschall

Matthias Marschall is a Software Engineer "made in Germany". His four children make sure that he feels comfortable in lively environments, and stays in control of chaotic situations. A lean and agile engineering lead, he's passionate about continuous delivery, infrastructure automation, and all things DevOps. In recent years, Matthias has helped build several web-based businesses, first with Java and then with Ruby on Rails. He quickly grew into system administration, writing his own configuration management tool before migrating his whole infrastructure to Chef in its early days. In 2008, he started a blog (http://www.agileweboperations.com) together with Dan Ackerson. There, they have shared their ideas about DevOps since the early days of the continually emerging movement. You can find him on Twitter as @mmarschall. Matthias holds a Master's degree in Computer Science (Dipl.-Inf. (FH)) and teaches courses on Agile Software Development at the University of Augsburg. When not writing or coding, Matthias enjoys drawing cartoons and playing Go. He lives near Munich, Germany.
Read more about Matthias Marschall