Knife Upload Error: Attempt to Use Relative Path
In one case yous've created your recipes and other objects for your chef cookbook, it should be uploaded to the Chef server.
At that place are ii ways you can upload your cookbooks:
- Using knife cookbook sub-command – This helps you to dispense your cookbooks
- Using knife upload sub-command – This helps you to upload all chef objects (including cookbooks, environments, nodes, etc.)
This tutorial explains how to use both of these sub-commands (pocketknife cookbook and pocketknife 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 Fifty-fifty When Information technology'southward not Changed Locally
- Perform Dry Run to Verify What'll become Uploaded
- Recursive and Concurrency Options
- Chef Repo Way Option
- Delete Cookbook from Chef Server
I. Knife Cookbook Sub-control
1. Upload Single Cookbook
Using the knife cookbook sub-command, you tin 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 Knife Cookbook Command Examples
To upload a single cookbook, use the following syntax:
knife cookbook upload [cookbook-name]
Using knife cookbook sub-control, the post-obit will upload a cookbook to the Chef server. The following will upload the cookbook called thegeekstuff.
Earlier you lot upload your cookbook, brand sure you working directory is your local chef repository directory. In this example, it is ~/chef-repo. The following uploads prod-db cookbook.
# cd ~/chef-repo # knife cookbook upload prod-db Uploading prod-db [i.0.0] Uploaded 1 cookbook.
Annotation: When you do an cookbook upload, only the files that doesn't already be in the chef server will be upload. So, this is kind of an incremental upload.
2. Upload ALL Cookbooks
If yous want to upload multiple cookbooks, use the -a pick as shown below.
The following will upload all the bachelor cookbooks on your local chef workstation from the current directory.
The following command will upload all your local cookbooks to chef server.
# pocketknife cookbook upload -a Uploading prod-db [1.0.0] Uploading thegeekstuff [ii.1.0] Uploaded all cookbooks.
Note: If you don't desire to upload all the files from the cookbooks, you tin use the chefignore file to exclude certain file types. For example, y'all can exclude .git files (or other temporary files) past specifying them in the chefignore file.
Yous can likewise use –all instead of -a choice.
knife cookbook upload --all
If yous are execute the upload command outside your chef-repo directory, you'll go the following " Your private key could not be loaded from /etc/chef/client.pem" Fault message.
# pocketknife cookbook upload -a WARNING: No knife configuration file found WARN: Failed to read the individual primal /etc/chef/client.pem: #<Errno::ENOENT: No such file or directory @ rb_sysopen - /etc/chef/client.pem> ERROR: Your individual fundamental could not be loaded from /etc/chef/client.pem Check your configuration file and ensure that your individual primal is readable
3. Freeze Cookbook Version (and Forcefulness Upload)
In one case you've done all your piece of work on a particular version of the cookbook, you can execute the following control, which will freeze that particular version.
# knife cookbook upload prod-db --freeze Uploading prod-db [1.0.0] Uploaded 1 cookbook.
In this example, the 1.0.0 version of prod-db cookbook is frozen. This means that if yous want to change prod-db, you lot should create a new version of the cookbook, and upload the new version.
If you are trying to update a frozen cookbook, you'll get the following error message:
# knife cookbook upload prod-db Uploading prod-db [i.0.0] Mistake: Version 1.0.0 of cookbook prod-db is frozen. Apply --force to override. Alarm: Not updating version constraints for prod-db in the environment as the cookbook is frozen. ERROR: Failed to upload i cookbook.
Simply, for some reason, if you want to update a fronzen cookbook, then utilize the –force option equally shown below.
# pocketknife cookbook upload prod-db --force Uploading prod-db [1.0.0] Uploaded i cookbook.
Note: During a cookbook upload, if you have empty directory on your local car, they'll not exist uploaded to the Chef server. If you lot want empty directories to be upload, add some hidden files like .empty inside the empty directory. In that case, technically that directory is not empty, and it volition exist uploaded by the knife cookbook upload command.
4. Upload Cookbook with All Dependencies
When you are uploading a unmarried cookbook, you lot can also use -d pick (or) –include-dependencies to upload all the dependent cookbooks automatically as shown below.
pocketknife cookbook upload thegeekstuff -d knife cookbook upload thegeekstuff --include-dependencies
5. Increase Number of Concurrent Connections
Past default, the number of concurrent connections the knife command uses for uploading the cookbooks to the chef server is x. This default value is adept enough for nearly state of affairs. But, if you are having 100s of large cookbooks, you can speed-upwards the upload procedure past increasing the concurrency value as shown below.
# knife cookbook upload -a --concurrency 20
six. Specify Cookbook Directory Location
Yous tin can likewise specify the location of your cookbook using the -o option. Here, you tin specify more than 1 directory location every bit shown beneath. This will look for the cookbook to be uploaded in the specified directory.
# knife cookbook upload prod-db -o /root/chef-repo/cookbooks Uploading prod-db [i.1.0] Uploaded ane cookbook.
When specifying multiple cookbook directories, separate them with colon as shown below.
# knife cookbook upload prod-db -o /root/chef-repo/cookbooks:/habitation/chef/cookbooks
You tin can as well employ –cookbook-path, which is same as the -o choice
# pocketknife cookbook upload prod-db --cookbook-path /root/chef-repo/cookbooks # knife cookbook upload prod-db --cookbook-path /root/chef-repo/cookbooks:/dwelling/chef/cookbooks
II. Knife Upload Sub-command
Knife 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-control
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 motorcar to the Chef Server.
# knife upload cookbooks/prod-db Updated cookbooks/prod-db
Delight note that this will do the upload only if anything is changed in the cookbook locally.
8. Upload ALL Cookbooks
First, 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
You can also upload cookbooks from anywhere within the chef repository. For this, specify / in front of cookbooks directory proper noun as shown beneath.
# pocketknife upload /cookbooks Updated cookbooks/prod-db Updated cookbooks/thegeekstuff
In the above instance, we are in the ~/chef-repo/nodes directory, and uploading all the cookbooks.
9. Upload Roles, Nodes and Environments
To upload the roles JSON files, execute the following:
knife upload roles
To upload the nodes JSON files, execute the post-obit:
# knife upload nodes Created nodes/webserver.json
To upload environments, do the post-obit:
knife upload environments
For the roles/nodes/environments, just like cookbooks, you can specify / in front of the directory, and execute the following command from anywhere inside your local chef repository directory.
knife upload /roles knife upload /nodes knife upload /environments
Too, you lot tin upload a specific JSON file for either roles or nodes or environments past specifying the name of the JSON file every bit 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.
# knife 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 inside your local chef repository directory.
knife upload /
Or, you selectively upload few object types. For example, the following will upload the cookbooks and nodes that friction match the given pattern.
# knife upload cookbooks/prod* nodes/web* Updated nodes/webserver.json Updated cookbooks/prod-db
11. Force Upload fifty-fifty when it'south non Inverse Locally
Just like the cookbook sub-command, the upload sub-command likewise supports freeze and forcefulness selection as shown below.
knife upload cookbooks/prod-db --freeze
One time a cookbook is frozen, you lot can upload the same version anymore as shown below.
# knife upload cookbooks/prod-db Mistake: cookbooks failed to write: Cookbook prod-db is frozen
Once a item 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
Note: Please notation that, –force command can exist used not just to update a frozen version, but also to update all the files in the chef server, even when the file is non inverse locally.
For example, the following updates only prod-db, as only that particular cookbook was inverse locally.
# knife upload cookbooks Updated cookbooks/prod-db
But, when you give –force, all the local cookbooks will be uploaded even if they are not changed locally.
# knife upload cookbooks --force Updated cookbooks/prod-db Updated cookbooks/thegeekstuff ..
12. Perform Dry Run to Verify what'll get Uploaded
Dry run is very helpful if y'all really desire to run into what local cookbooks are changed, which volition be uploaded to the chef server. This way, yous can brand certain the upload control will upload what y'all are actually expecting information technology to upload.
The following shows that this would upload simply the prod-db and webserver cookbook. Nothing is really uploaded. This is just a dry run.
# knife upload cookbooks --force --dry out-run Would update cookbooks/prod-db Would update cookbooks/webserver
13. Recursive and Concurrency Options
By default, the knife upload command, does all the upload recursively. If y'all don't desire recursive upload, yous can specify no-recurse as shown beneath.
knife upload cookbooks --no-recurse
By default the number of concurrent connections the knife upload command will use is 10. If you accept 100s of objects in your local machine that should be uploaded to the chef server, you tin can increase the concurrent connections to upload as shown beneath.
knife upload cookbooks --concurrency 20
fourteen. Chef Repo-Mode 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 post-obit are the 3 possible value for chef repo way:
- static
- everything
- hosted_everything
You tin can also use static if you are using only cookbooks, roles, environments and data numberless as shown below.
# 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 lot attempt to use everything repo-manner, information technology will give the following mistake message:
# knife upload cookbooks --dry-run --repo-mode everything Alert: Y'all have repo_mode set up to 'everything', but your chef_server_url looks like it might exist a hosted setup. If this is the example delight use hosted_everything or permit repo_mode to default
In this case, use the hosted_everything mode as shown beneath.
# knife upload cookbooks --repo-fashion 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.
First, 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 you view the cookbooks in the Chef server, y'all'll still see the erased prod-db cookbook.
# pocketknife cookbook list thegeekstuff 0.2.0 webserver 0.ane.0 prod-db 0.one.0
So, to permanently delete it from the Chef server, utilize the –purge option as shown below.
# knife upload cookbooks --purge Deleted actress entry cookbooks/prod-db (purge is on)
After the purge, nosotros will not encounter the prod-db cookbook on the remote server anymore as shown below.
# knife cookbook list thegeekstuff 0.ii.0 webserver 0.1.0
Source: https://www.thegeekstuff.com/2017/01/chef-knife-cookbook-upload/
0 Response to "Knife Upload Error: Attempt to Use Relative Path"
ارسال یک نظر