How to Upload Cookbook to Chef Server
Once you lot've created your recipes and other objects for your chef cookbook, it should be uploaded to the Chef server.
At that place are two ways you tin upload your cookbooks:
- Using knife cookbook sub-command – This helps you to manipulate your cookbooks
- Using knife upload sub-control – This helps you lot to upload all chef objects (including cookbooks, environments, nodes, etc.)
This tutorial explains how to use both of these sub-commands (knife cookbook and knife upload) with examples.
The following are covered in this tutorial:
- Upload Single Cookbook
- Upload ALL Cookbooks
- Freeze Cookbook Version (and Force Upload)
- Upload Cookbook with All Dependencies
- Increase Number of Concurrent Connections
- Specify Cookbook Directory Location
- Upload cookbooks using upload sub-command
- Upload ALL Cookbooks (using upload sub-command)
- Upload Roles, Nodes and Environments
- Upload the Whole Chef Repo (or) Upload Selective Items
- Force Upload Even When Information technology's not Changed Locally
- Perform Dry out Run to Verify What'll get Uploaded
- Recursive and Concurrency Options
- Chef Repo Style Option
- Delete Cookbook from Chef Server
I. Knife Cookbook Sub-command
1. Upload Unmarried Cookbook
Using the knife cookbook sub-command, you lot can perform all kinds of operations on your cookbooks including create, delete, upload, lock, view, etc.
To create a new Chef cookbook, refer to this: 12 Chef Pocketknife Cookbook Command Examples
To upload a single cookbook, use the following syntax:
knife cookbook upload [cookbook-proper noun]
Using knife cookbook sub-control, the following will upload a cookbook to the Chef server. The following will upload the cookbook called thegeekstuff.
Earlier you upload your cookbook, make sure you working directory is your local chef repository directory. In this example, information technology is ~/chef-repo. The following uploads prod-db cookbook.
# cd ~/chef-repo # knife cookbook upload prod-db Uploading prod-db [1.0.0] Uploaded 1 cookbook.
Annotation: When yous do an cookbook upload, only the files that doesn't already exist in the chef server will be upload. So, this is kind of an incremental upload.
2. Upload ALL Cookbooks
If you lot want to upload multiple cookbooks, use the -a pick equally shown below.
The following will upload all the available cookbooks on your local chef workstation from the electric current directory.
The following command will upload all your local cookbooks to chef server.
# knife cookbook upload -a Uploading prod-db [1.0.0] Uploading thegeekstuff [ii.1.0] Uploaded all cookbooks.
Annotation: If you lot don't want to upload all the files from the cookbooks, yous can use the chefignore file to exclude certain file types. For example, y'all tin exclude .git files (or other temporary files) by specifying them in the chefignore file.
Yous can also use –all instead of -a option.
knife cookbook upload --all
If you lot are execute the upload control outside your chef-repo directory, you'll get the following " Your individual key could not be loaded from /etc/chef/customer.pem" ERROR message.
# knife cookbook upload -a WARNING: No knife configuration file institute WARN: Failed to read the private central /etc/chef/client.pem: #<Errno::ENOENT: No such file or directory @ rb_sysopen - /etc/chef/client.pem> ERROR: Your private cardinal could non be loaded from /etc/chef/client.pem Check your configuration file and ensure that your private cardinal is readable
3. Freeze Cookbook Version (and Force Upload)
Once you lot've done all your work on a particular version of the cookbook, you lot tin can execute the following command, which will freeze that detail version.
# knife cookbook upload prod-db --freeze Uploading prod-db [one.0.0] Uploaded 1 cookbook.
In this case, the 1.0.0 version of prod-db cookbook is frozen. This means that if you want to alter prod-db, yous should create a new version of the cookbook, and upload the new version.
If you are trying to update a frozen cookbook, you'll go the following error bulletin:
# knife cookbook upload prod-db Uploading prod-db [1.0.0] Fault: Version 1.0.0 of cookbook prod-db is frozen. Apply --strength to override. Alarm: Not updating version constraints for prod-db in the surround as the cookbook is frozen. ERROR: Failed to upload ane cookbook.
Simply, for some reason, if yous desire to update a fronzen cookbook, then use the –force option as shown below.
# knife cookbook upload prod-db --force Uploading prod-db [1.0.0] Uploaded one cookbook.
Note: During a cookbook upload, if you accept empty directory on your local car, they'll not be uploaded to the Chef server. If you desire empty directories to be upload, add some hidden files like .empty inside the empty directory. In that example, technically that directory is not empty, and it will exist uploaded by the pocketknife cookbook upload control.
four. Upload Cookbook with All Dependencies
When yous are uploading a single cookbook, you tin can as well use -d option (or) –include-dependencies to upload all the dependent cookbooks automatically as shown below.
knife cookbook upload thegeekstuff -d pocketknife cookbook upload thegeekstuff --include-dependencies
five. Increase Number of Concurrent Connections
By default, the number of concurrent connections the knife command uses for uploading the cookbooks to the chef server is ten. This default value is good enough for well-nigh situation. But, if you are having 100s of large cookbooks, yous can speed-up the upload process by increasing the concurrency value as shown below.
# pocketknife cookbook upload -a --concurrency 20
6. Specify Cookbook Directory Location
Y'all tin also specify the location of your cookbook using the -o option. Here, y'all can specify more than than one directory location as shown beneath. This will look for the cookbook to be uploaded in the specified directory.
# pocketknife cookbook upload prod-db -o /root/chef-repo/cookbooks Uploading prod-db [i.1.0] Uploaded one cookbook.
When specifying multiple cookbook directories, separate them with colon every bit shown below.
# knife cookbook upload prod-db -o /root/chef-repo/cookbooks:/home/chef/cookbooks
You can also apply –cookbook-path, which is same as the -o pick
# knife cookbook upload prod-db --cookbook-path /root/chef-repo/cookbooks # knife cookbook upload prod-db --cookbook-path /root/chef-repo/cookbooks:/home/chef/cookbooks
Two. Knife Upload Sub-command
Pocketknife upload sub-command is used to upload all chef objects including cookbooks. For example, you can use this to upload cookbooks, roles, surround variables, etc.
7. Upload Cookbooks using Upload sub-command
To upload a specific cookbook, go to the chef-repo directory, specify the cookbook name along with the cookbook directory as shown below. This will upload prod-db cookbook from local automobile to the Chef Server.
# knife upload cookbooks/prod-db Updated cookbooks/prod-db
Please note that this will do the upload only if anything is inverse in the cookbook locally.
viii. Upload ALL Cookbooks
Kickoff, cd to the chef repository directory, and execute the following, which will upload all the cookbooks from your local machine.
# cd chef-repo # knife upload cookbooks Updated cookbooks/prod-db Updated cookbooks/thegeekstuff
Yous tin besides upload cookbooks from anywhere within the chef repository. For this, specify / in front of cookbooks directory name as shown below.
# knife upload /cookbooks Updated cookbooks/prod-db Updated cookbooks/thegeekstuff
In the above case, nosotros are in the ~/chef-repo/nodes directory, and uploading all the cookbooks.
nine. Upload Roles, Nodes and Environments
To upload the roles JSON files, execute the following:
pocketknife upload roles
To upload the nodes JSON files, execute the following:
# knife upload nodes Created nodes/webserver.json
To upload environments, exercise the following:
knife upload environments
For the roles/nodes/environments, just like cookbooks, you can specify / in front of the directory, and execute the post-obit control from anywhere within your local chef repository directory.
pocketknife upload /roles knife upload /nodes knife upload /environments
As well, you can upload a specific JSON file for either roles or nodes or environments by specifying the name of the JSON file as shown below.
knife upload roles/dba.json knife upload nodes/webserver.json knife upload environment/oracledb.json
10. Upload the Whole Chef Repo (or) Upload Selective Items
To upload your entire local chef repository to your server, cd to the chef-repo directory and execute the following.
# pocketknife upload . Updated nodes/webserver.json Updated cookbooks/prod-db Updated cookbooks/thegeekstuff Updated roles/dba.json ..
The following is same as the above command, except this can be executed from anywhere within your local chef repository directory.
pocketknife upload /
Or, y'all selectively upload few object types. For example, the post-obit volition upload the cookbooks and nodes that lucifer the given blueprint.
# knife upload cookbooks/prod* nodes/web* Updated nodes/webserver.json Updated cookbooks/prod-db
xi. Force Upload even when it's not Changed Locally
Just like the cookbook sub-command, the upload sub-command likewise supports freeze and force option as shown below.
knife upload cookbooks/prod-db --freeze
Once a cookbook is frozen, you tin upload the same version anymore as shown below.
# pocketknife upload cookbooks/prod-db Error: cookbooks failed to write: Cookbook prod-db is frozen
Once a particular version of a cookbook is frozen, for some reason, if yous want to update that without creating a new version, use the –force as shown below.
# knife upload cookbooks/prod-db --force Updated cookbooks/prod-db
Annotation: Please note that, –force command can be used non only to update a frozen version, but also to update all the files in the chef server, even when the file is not changed locally.
For instance, the following updates only prod-db, every bit only that particular cookbook was changed locally.
# knife upload cookbooks Updated cookbooks/prod-db
Only, when y'all give –force, all the local cookbooks will be uploaded even if they are non changed locally.
# knife upload cookbooks --force Updated cookbooks/prod-db Updated cookbooks/thegeekstuff ..
12. Perform Dry Run to Verify what'll become Uploaded
Dry out run is very helpful if you lot really want to meet what local cookbooks are changed, which volition be uploaded to the chef server. This style, you can brand certain the upload control will upload what you are really expecting it to upload.
The following shows that this would upload merely the prod-db and webserver cookbook. Nil is really uploaded. This is but a dry run.
# pocketknife upload cookbooks --force --dry-run Would update cookbooks/prod-db Would update cookbooks/webserver
13. Recursive and Concurrency Options
By default, the pocketknife upload command, does all the upload recursively. If you don't desire recursive upload, yous tin specify no-recurse every bit shown below.
pocketknife upload cookbooks --no-recurse
Past default the number of concurrent connections the pocketknife upload control will utilize is ten. If you lot have 100s of objects in your local motorcar that should be uploaded to the chef server, you can increase the concurrent connections to upload as shown below.
knife upload cookbooks --concurrency twenty
fourteen. Chef Repo-Manner Option
The default repo mode used by the knife upload command is either everything or hosted_everything depending on how your chef server setup.
The following are the three possible value for chef repo style:
- static
- everything
- hosted_everything
Yous can also employ static if you are using only cookbooks, roles, environments and data numberless as shown beneath.
# knife upload cookbooks --repo-mode static Updated cookbooks/thegeekstuff Updated cookbooks/webserver Updated cookbooks/prod-db
For your local chef server (Which is installed on your own server), if you attempt to employ everything repo-mode, information technology will give the post-obit error message:
# pocketknife upload cookbooks --dry-run --repo-mode everything Alarm: You take repo_mode fix to 'everything', only your chef_server_url looks like it might be a hosted setup. If this is the case please apply hosted_everything or allow repo_mode to default
In this case, use the hosted_everything mode as shown below.
# knife upload cookbooks --repo-manner hosted_everything Updated cookbooks/thegeekstuff Updated cookbooks/webserver Updated cookbooks/prod-db
15. Delete Cookbook from Chef Server
If you've removed a cookbook from your local chef workstation, it will still exist there on your chef server.
Starting time, remove a cookbook from your local server.
cd ~/chef-repo rm -rf prod-db
Force upload all your local cookbooks
# knife upload cookbooks --force Updated cookbooks/thegeekstuff Updated cookbooks/webserver
But, if yous view the cookbooks in the Chef server, you'll still come across the erased prod-db cookbook.
# pocketknife cookbook list thegeekstuff 0.ii.0 webserver 0.1.0 prod-db 0.ane.0
So, to permanently delete it from the Chef server, utilize the –purge pick as shown beneath.
# knife upload cookbooks --purge Deleted extra entry cookbooks/prod-db (purge is on)
After the purge, nosotros will non run into the prod-db cookbook on the remote server anymore every bit shown below.
# knife cookbook list thegeekstuff 0.2.0 webserver 0.1.0
mcintoshwitiontis.blogspot.com
Source: https://www.thegeekstuff.com/2017/01/chef-knife-cookbook-upload/#:~:text=7.-,Upload%20Cookbooks%20using%20Upload%20sub%2Dcommand,machine%20to%20the%20Chef%20Server.
Posting Komentar untuk "How to Upload Cookbook to Chef Server"