Reputation: 1334
I'm trying to modify and upload a cookbook to my Chef server but when I try that, it looks like the recipe inside the cookbook is not changed in Chef server.
I am using a Win2K8 machine as my workstation, and I edit the learn_chef_iis-0.2.0\recipes\default.rb. I then do:
knife cookbook delete learn_chef_iis
then:
knife cookbook upload learn_chef_iis
and when I look at the default.rb in the opcode web app, it still shows the same default.rb (i.e., my changes are not there).
I've seen some suggestions to change the version of the cookbook and I've tried that by editing the metadata.rb "version", but even when I do that, when I do the "knife cookbook upload" I still end up with the same version (0.2.0) and with the unmodified default.rb.
HELP!!! I've been working on this for awhile today and am stuck :(!!
Thanks,
PS C:\Users\Administrator\chef-repo\learn_chef_iis-0.2.0> knife cookbook upload learn_chef_iis
Uploading learn_chef_iis [0.2.0]
Uploaded 1 cookbook.
PS C:\Users\Administrator\chef-repo\learn_chef_iis-0.2.0> knife cookbook upload learn_chef_iis --force
Uploading learn_chef_iis [0.2.0]
Uploaded 1 cookbook.
PS C:\Users\Administrator\chef-repo\learn_chef_iis-0.2.0>
EDIT:
Here's the modified default.rb. Is this ok? Maybe this default.rb is bad so it causes the "knife upload" to fail?
#
# Cookbook Name:: learn_chef_iis
# Recipe:: default
#
# Copyright (C) 2014
#
#
#
powershell_script 'Install IIS' do
code <<-EOH
Import-Module ServerManager
Add-WindowsFeature Web-Server
EOH
guard_interpreter :powershell_script
not_if "(Get-WindowsFeature -Name Web-Server).InstallState -eq 'Installed'"
end
service 'w3svc' do
action [:enable, :start]
end
template 'c:\inetpub\wwwroot\Default.htm' do
source 'index.html.erb'
end
and, here's a run with "verbose" output:
PS C:\Users\Administrator\chef-repo> knife cookbook upload learn_chef_iis -V
INFO: Using configuration from C:/Users/Administrator/chef-repo/.chef/knife.rb
Uploading learn_chef_iis [0.2.0]
INFO: Validating ruby files
INFO: Validating templates
INFO: Syntax OK
INFO: Saving learn_chef_iis
INFO: Uploading files
INFO: Upload complete!
Uploaded 1 cookbook.
PS C:\Users\Administrator\chef-repo>
EDIT 3:
I don't have an explanation, but I created a new cookbook following:
http://learn.chef.io/learn-the-basics/windows/make-your-recipe-more-manageable/
This one is named "iis".
Then I did "knife cookbook upload iis" and that worked, and I did "chef-client -o "recipe[iis]" on the node and that worked.
I then modified the recipe slightly and did the knife upload and chef-client again and saw the updated info on the IIS.
So, the new cookbook seems to be working and updating.
Strange :(???
Upvotes: 2
Views: 10276
Reputation: 15784
According to what you describe your probably have 2 entries in your knife.rb
for the cookbook_path
setting (it takes an array) See the doc.
I'm pretty sure the original cookbook is on the last path listed in the cookbook_path
so knife upload don't fail but it upload the unmodified version.
When you're unsure of where you're living or if you wish to upload a cookbook from a path not in the cookbook_path
you can override this setting with -o .
when you're on the parent directory for the cookbook or -o /absolut/path/to/parent/dir/
.
When you're unsure about a command type it without arguments, the help will be displayed.
>knife cookbook upload
USAGE: knife cookbook upload [COOKBOOKS...] (options)
-a, --all Upload all cookbooks, rather than just a single cookbook
-s, --server-url URL Chef Server URL
--chef-zero-host HOST Host to start chef-zero on
--chef-zero-port PORT Port to start chef-zero on
-k, --key KEY API Client Key
--[no-]color Use colored output, defaults to false on Windows, true otherwise
--concurrency NUMBER_OF_THREADS
How many concurrent threads will be used
-c, --config CONFIG The configuration file to use
-o, --cookbook-path PATH:PATH A colon-separated path to look for cookbooks in
--defaults Accept default values for all questions
--include-dependencies Also upload cookbook dependencies
-d, --disable-editing Do not open EDITOR, just accept the data as is
-e, --editor EDITOR Set the editor to use for interactive commands
-E, --environment ENVIRONMENT Set ENVIRONMENT's version dependency match the version you're uploading.
--force Update cookbook versions even if they have been frozen
-F, --format FORMAT Which format to use for output
--freeze Freeze this version of the cookbook so that it cannot be overwritten
-z, --local-mode Point knife commands at local repository instead of server
-u, --user USER API Client Username
--print-after Show the data after a destructive operation
-V, --verbose More verbose output. Use twice for max verbosity
-v, --version Show chef version
-y, --yes Say yes to all prompts for confirmation
-h, --help Show this message
And when you're wondering what it does or where it search for something, run knife in verbose mode with -VV
which gives you a lot of informations:
Extract of an upload with -VV:
[...]
Uploading company-collectd [0.1.0]
DEBUG: Versions of cookbook 'collectd' returned by the server: 1.1.2
DEBUG: Matched cookbook 'collectd' with constraint '>= 0.0.0' to cookbook version '1.1.2' on the server
DEBUG: No chefignore file found at d:/chef/repo/cookbooks/chefignore no files will be ignored
INFO: Validating ruby files
DEBUG: Ruby file d:/chef/repo/cookbooks/company-collectd/attributes/default.rb is unchanged, skipping syntax check
DEBUG: Ruby file d:/chef/repo/cookbooks/company-collectd/metadata.rb is unchanged, skipping syntax check
DEBUG: Ruby file d:/chef/repo/cookbooks/company-collectd/recipes/default.rb is unchanged, skipping syntax check
INFO: Validating templates
INFO: Syntax OK
[...]
Upvotes: 1
Reputation: 6258
I'm assuming your chef repo is essentially structured something like this:
cookbooks/your_cookbook
Containing:
metadata.rb
recipes/default.rb
providers/
resources/
If you incremented the version number in metadata.rb
and are sure you are running
knife cookbook upload
in the directory, everything should work. At least that's what the docs say.
Or you could try to back out of that directory into your main directory of your chef repo and run:
knife upload cookbooks
or
knife upload /
Again, that's what the docs say.
But I don't have a lot of experience using this. I use Berkshelf which is essential a dependency management tool that's a lot more seemless than Librarian-Chef, in my opinion.
Simply navigate to your cookbook, run:
berks init
and then when you make changes run through:
berks install
berks upload
to push your cookbooks to your chef repo, after updating your version number in your metadata.rb
file.
Hope this helps you!
Upvotes: 1