Chef knife configuration - ruby

I feel silly asking this question as it seems to work flawlessly for most people but I couldn't solve the following problem I encountered after setting up a Chef server 12 on RHEL 6 and the ChefDK 0.6.0 on my mac.
The chef server setup went through like charm as describeb on the documentation, no errors at all. When I wanted to use my machine as workstation to push cookbooks to the server I always get the error "The object you are looking for could not be found". According to other stackoverlfow posts (0, 1, 2) this is likely due to a configuration issue in knife.rb. Nevertheless, I used "knife configure" to setup the knife.rb file and double checked for any typos in the path. In addition, according to the knife.rb documentation page I used the attributes properly.
Anyone have an idea what could cause the problem?
log_level :info
log_location STDOUT
node_name "nodermatt"
client_key "/Users/odermatt/chef-repo/.chef/nodermatt.pem"
validation_client_name "Adobe-validator.pem"
validation_key "/Users/odermatt/chef-repo/.chef/Adobe-validator.pem"
chef_server_url "https://sj1010005158157.corp.adobe.com:443/organizations/Adobe"
syntax_check_cache_path "/Users/odermatt/chef-repo/.chef/syntax_check_cache"
cookbook_path [ "/Users/odermatt/chef-repo/cookbooks" ]

You need to do perform knife commands under .chef directory. I too had same problem for change I tried under .chef directory, it was working. Try "knife client check" and "knife cookbook upload yourcookbook".
In knife.rb file, give chef_server_url as with your orgs name means which org you need to upload the cookbook. Typically be like "https://api.chef.io/organizations/orgname" and give path to your cookbooks directory.

I had this same issue, could not run
knife node run_list add nodename 'recipe[cron-delvalidate::default]' - cron-delvalidator recipe to the node named: chefnode
I found out, after reading this that it's Chefnode, not chefnode, capital "C". This solved my issue.
The response was:
Chefnode:
run_list: recipe[cron-delvalidate::default]

Related

kubectl not working on my windows 10 machine

When I try to run any kubectl command including kubectl version, I get a pop-up saying "This app can't run on your PC, To find a version for your PC, check with the software publisher" when this is closed, the terminal shows "access denied"
The weird thing is, when I run the "kubectl version" command in the directory where I have downloaded kubectl.exe, it works fine.
I have even added this path to my PATH variables.
thank you for the answer, #rally
apparently, in my machine, it was an issue of administrative rights during installation. My workplace's IT added the permission and it worked for me.
Adding this answer here so that if anyone else comes across this problem they can try this solution as well.
Not knowing what exactly you downloaded, i would suggest you to delete everying in the folder and follow the instructions for installing kubectl for Windows from here:
https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/
Note: downloading the .exe is not enough. You need a kubeconfig file "config", which contains the configuration to access your cluster.
kubectl looks for this file in a hidden folder under your user profile directory. c:\users<me>.kube.
Just to let you try, i would suggest you to activate Kubernetes in your Docker-Desktop installation. I guess you have this installed. If not install it from the Dockersite. https://www.docker.com/products/docker-desktop/
Activating Kubernetes inside Docker-desktop, will install also kubectl and save the config in the .kube folder.
After the installation finished, in a new terminal:
kubectl get node
You should see the 1 node in the kubernetes-docker-desktop cluster.
Now if you want to access another cluster, you need the kubeconfig-file for that cluster. If you have it, just rename the config in the .kube folder (to not loose it) and put the other config inside.
If the new config file is correct you should be able to access that cluster.
The config file can be structured to hold more than one cluster configuration and you can switch between them using a so called context.
Here you can get the information how to do that, according to your needs:
https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/
Hope this can help you, starting with KUbernetes.

How to add cookbooks from chef documentation

I am a new to chef cookbooks and currently working on a task. I have already completed the tutorial on chef.io but i am struggling to understand how can i install a cookbook provided at chef-io.
So as of now, I have downloaded the cookbook. Its .tar file and i extracted it. I can see respective default.rb and other files but i am unable to get that how can i add this cookbook to my existing cookbooks which are creating a vm image.
Is there any guide or tutorial that i can follow ?
In addition to Josh's answer it sounds to me like want to add it to your chef-repo after downloading it and extracting the gzip file?
Just add the maven directory to your cookbooks directory. Or you could just do knife cookbook site install maven from within your chef-repo directory.
Or maybe you want to upload it to your Chef Server?
knife cookbook upload maven See: https://docs.chef.io/knife_cookbook.html#upload
If I'm understanding your question correctly, then what you need to do is create a Chef role, and then list all of the recipes that you want to execute in your role's run_list. As for documentation, check out Chef's documentation on roles: Chef Roles
Firstly if i get your question right, you are trying to download an already existing cookbook from the community. If so, you can follow these steps :
1) Download the cookbook which is in the .tar format as you specified, extract it and place that particular cookbook within your chef-repo path from where you want to upload it.
2) Once done, do a "knife cookbook upload cookbook-name"
Now the main part is, if you are trying to upload this cookbook and make it part of your already existing run-list. You need to add this within the run-list.
Else if you are doing it via role, you will need to add this cookbook recipe within your role's run-list.
But keep in mind, whatever cookbook's you download from the community might have dependencies on other cookbook's so choose wisely. The lesser cookbook's the better as this makes your run-list converge faster for a faster chef-client run.
Hope this helps.
Regards,
Akshay

Error when running vagrant: "The host path of the shared folder is missing"

I have downloaded a Vagrantfile, but when i run vagrant up in terminal the following message appears:
Bringing machine 'default' up with 'virtualbox' provider... There are
errors in the configuration of this machine. Please fix the following
errors and try again:
vm:
* The host path of the shared folder is missing: ~/Sync
OBS.: Using Ubuntu 14.10
I created a folder named Sync in my home.
According to Vagrant docs host path must be either absolute (i.e. /home/user/Sync) or relative to project root (place where your Vagrantfile is).
Relative to project root means if your Vagrantfile resides in /home/user/MyProject then setting up path as "Sync" will create share from /home/user/MyProject/Sync.
Ref: http://docs.vagrantup.com/v2/synced-folders/basic_usage.html
I assumed you are in linux or mac. Type in "pwd" and enter in the terminal where Homestead.yml is.
Mine is "/home/idhamhafidz/Code/opp190-ama"
Then go to your Homestead.yml and edit the folders section like in the image below:
Then quit edit Homesteady.yml and re-run vagrant up again.
In my case it was a space at the end of the path in config.yaml:
source: '/Users/h/Packt/Code '
I've deleted this space and it's working now.
If you are using Vagrant and Windows Subsystem for Linux then you can solve the issue creating a symlink
ln -s /mnt/c/Users/user/project ~/project
/mnt/c/Users/user/project should match the Vagrant project in your Windows machine.
~/project should match the path that is missing.
Note, that you may need to create any intermediary directories.
I know this is an old question, but for anyone just encountering this issue and having a hard time finding a conclusion the answer by #megawebmaster would be the correct approach in giving the relative path to the folder: "/home/(your-pc-username)/Sync/".
Also with a Vagrantfile being ruby-based I personally use ruby's ENV object:
#{ENV["HOME"]}/Sync should resolve the issue.
I came across the same problem and
mkdir ~/Sync help me solve it.

vagrant 1.5.4 chef_solo encrypted data bag

I am running vagrant 1.5.4. in any previous releases i could set the chef_solo provisioner configuration to reference the encrypted data bag key as it appears here, but now I receive the following message, see the snippet below:
$ vagrant --version
Vagrant 1.5.4
$ vagrant up
...
DEPRECATION: Chef encrypted_data_bag_secret has no effect anymore.
Remove this from your Vagrantfile since it'll be removed in the next
Vagrant version.
...
ERROR: Is a directory - /tmp/vagrant-chef-2/encrypted_data_bag_secret_key
FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Sometimes I receive the message
ERROR: No secret specified to load_secret and no secret found at /etc/chef/encrypted_data_bag_secret
Any idea how this issue can be resolved, or shall I downgrade?
UPDATE 1:
investigating the changes (on a different provisioner) reveals that encrypted_data_bag_secret_key_path still exist, and even though I set it to reference the correct path, I still get the deprecation message above. Besides I wonder which file is being resolved or used as the encrypted data bag file.
seems to be fixed if the attribute is changed from encrypted_data_bag_secret to encrypted_data_bag_secret_key_path. the latter is kinda misleading, it does not refer to the path, rather, it refers to the key itself.

Setting the Chef log level in knife ec2 when creating a server

I'm looking for the correct way to set chef-client's log level when creating a server using knife ec2.
My initial thought was setting the log level configuration in my knife.rb file like this:
log_level :debug
This didn't result in any visible change in the log level.
I also tried turning on the -VV option in knife ec2, but that just results in verbose output from knife ec2 itself.
When I run chef-client directly after logging onto the server, I can get debug information with no problems using:
sudo chef-client -l debug
That would be sufficient, but I'm investigating an underlying problem that only occurs on the initial server bootstrap.
Here is a simple hack/work-around that I discovered to control the log level. In knife.rb, include
a line like the following, for example:
chef_client_path 'chef-client -l debug'
You can see why this works by looking at
this line
of the Chef source code. I confirmed that this works in Chef 11.6.
It may work in other versions.
Currently the default bootstrap templates always set the default :auto log level to the node. There is at least one ticket that seems to be related.
So your only option now is to create your own bootstrap template that adds log_level :debug to /etc/chef/client.rb. You can copy and modify e.g. the default "chef-full" template and then pass it as a parameter to knife.

Resources