Muradin007
Muradin007

Reputation: 158

How to unfreeze cookbook

I discovered the ability to freeze a cookbook in chef accidentally through berks upload. It does sound great to be able to prevent changes and uploads to a cookbook. But...

How do you unfreeze a cookbook? I couldn't find any documentation or any posts asking this. It might sound counter-intuitive as to why, why would you want to do that...? You released your cookbook, you shouldn't make history changes.

What if though, you had a production emergency and the cookbook of that version broke everything. First answer might be, move forward and fix the issue --- but that could take awhile. Second answer might be, change the version pinned to the previous --- but what if you have 50 cookbooks pinned to that version? Also not practical.

Seems pretty useful to be able to unfreeze something. Yes, you can use the -f option to force the update. But having to force update every change in the future ad infinitum sounds janky and not proper. Especially when someone has accidentally frozen a cookbook (such as in my case).

Upvotes: 1

Views: 1954

Answers (4)

Daniel
Daniel

Reputation: 1

To unfreeze a frozen cookbook, all you need to do is to change the cookbook version written in the medatada.rb file that is probably located inside the directory of your cookbook. For example, assuming your cookbook directory is named 'my_cookbook':

  1. edit 'your_cookbook/metadata.rb'
  2. look for the line that says something like: "version '0.2.0'"
  3. update the version to a higher number like '0.3.0'
  4. save the changes
  5. try to upload your cookbook again like so: 'knife cookbook upload my_cookbook'

The reason is that you can freeze a cookbook you are uploading to prevent future overwrites of an existing good working cookbook in your Chef Infra server. If so, the version number in the metadata.db file in your local cookbook needs to be updated every time you make a change in a cookbook that has been frozen prior to uploading that cookbook to your Chef Infra server next time. So, if you need to upload a frozen cookbook without using the '--force' option, remember to always bump up the version number in the metadata.rb file of your cookbook. Otherwise either force the upload or delete the cookbook from your Chef Infra server and re-upload it once more without freezing it.

Check this book/chapter/section for more reference: https://subscription.packtpub.com/book/networking-&-servers/9781785287947/1/ch01lvl1sec24/freezing-cookbooks

Upvotes: 0

Eappan Benjamin
Eappan Benjamin

Reputation: 1

Just delete the version of that cookbook and reload. Try below:

knife cookbook delete <cookbook name>
knife cookbook upload <cookbook name>

Upvotes: 0

Carolinne Torres
Carolinne Torres

Reputation: 134

You can use berks upload --force specially when you accidentally frozen a cookbook version. I don't get your point to not use the force option.

$ berks help upload
Usage:
  berks upload [COOKBOOKS]

Options:
  -b, [--berksfile=PATH]                               # Path to a Berksfile to operate off of.
  -e, [--except=one two three]                         # Exclude cookbooks that are in these groups.
  -o, [--only=one two three]                           # Only cookbooks that are in these groups.
      [--no-freeze], [--no-no-freeze]                  # Do not freeze uploaded cookbook(s).
      [--force]                                        # Upload all cookbooks even if a frozen one exists on the Chef Server.
      [--ssl-verify], [--no-ssl-verify]                # Disable/Enable SSL verification when uploading cookbooks.
  -s, [--skip-syntax-check], [--no-skip-syntax-check]  # Skip Ruby syntax check when uploading cookbooks.
      [--halt-on-frozen], [--no-halt-on-frozen]        # Exit with a non zero exit code if the Chef Server already has the version of the cookbook(s).
  -c, [--config=PATH]                                  # Path to Berkshelf configuration to use.
  -F, [--format=FORMAT]                                # Output format to use.
                                                       # Default: human
  -q, [--quiet], [--no-quiet]                          # Silence all informational output.
  -d, [--debug], [--no-debug]                          # Output debug information

Upvotes: 1

coderanger
coderanger

Reputation: 54267

You can force-upload a new version with the freeze flag set to false. We do not specifically expose this or make it easy since it kind of defeats the point. The better solution is to either use SemVer pinning rather than single versions or use the newer Policyfile system.

Upvotes: 1

Related Questions