How to add cookbooks from chef documentation - maven

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

Related

Chef, related path from cookbook to file storage

Is it possibile to get absolute path to cookbook directory(I don't need path to cache).
What I want to do?
My structure:
Chef
-Cookbooks(tomcat, java, etc.)
-Profiles(json files with configs)
-Resources(zip files with programs)
runScript0.bat
runScript1.bat
....
How can I get path to Resources folder from recipes, I need to get files from this folder w/o hardcodded path. Of course I can download programs from svn/git, but I need this option too.
The structure you describe is not inside a cookbook so those files do not exist as far as Chef is concerned. Even inside a cookbook, you need to use a cookbook_file or remote_directory resource to write to a known place first.

'cookbook' is missing in the structure of knife solo init

When i type knife solo init . command, cookbook folder is not created in the basic structure.
I cannot find any reason why it is doing this.
my chef and knife are the latest version so far.
Your help will be highly appreciated!
You can see the code here: https://github.com/matschaffer/knife-solo/blob/v0.5.1/lib/chef/knife/solo_init.rb#L35
The only thing that would prevent it from making the cookbooks/ folder is if a file of the same name exists.

Where do you find the runlist (Vagrant)?

According to this link
Chef Solo error: Cookbook apt not found
it says, i have to add apt cookbook in runlist.
I downloaded the apt-cookbook but I don't know where the runlist is.
Help.
Where are you configuring this setup? If you are doing it on AWS Opswork then in that respective layer setup you can mention the runlist under its Recipe section.
One thing to note is that the sequence in runlist also matter, you should have to specify 'apt::default' first then other recipe.

How to get stand-alone ohai to recognize custom plugin_path?

I have chef configured to add "/etc/chef/ohai_plugins" to Ohai::Config[:plugin_path]. However, the Chef documentation says:
"The Ohai executable ignores settings in the client.rb file when Ohai is run independently of the chef-client."
So, how can I get a stand-alone run of ohai to load and use the plugins in that custom path?
(Background: I have a custom plugin that reports some information that we keep track of for a fleet of servers, like whether a server has been patched for heartbleed or shellshock. I want to be able to run "ssh somehost ohai", parse the JSON that gets sent back, and extract the information I need.)
Thanks.
Outside of chef, you can add an additional plugin path using the -d switch, e.g.
$ ohai -d /etc/chef/ohai_plugins
The relevant source code is at:
https://github.com/chef/ohai/blob/master/lib/ohai/application.rb#L25-L28
https://github.com/chef/ohai/blob/master/lib/ohai/application.rb#L78-L80
The option to specify a custom config file for Ohai was sadly removed last year with https://github.com/chef/ohai/commit/ebabd088673cf3e36d600bd96aeba004077842f1
Hope this answers your question.
This will be possible soon via the implementation of Chef RFC 53: https://github.com/chef/chef-rfc/blob/master/rfc053-ohai-config.md

where can I find source rpm for amzn repo?

I need to build a RPM package on my Centos6 EC2 instance, so I think it'll be best to use the "official" specs from amzn. Usually I did that with yumdownloader --source xxx but on the EC2 instance it cannot find any.
I checked /etc/yum.repo.d, which seems not to have any repo regarding src.
You can use the get_reference_source python script as described by Shadow Lau, but that needs the package being installed. And you need to run it on EC2 on an Amazon Linux AWS instance.
The script gets the URL to download from alami-source-request.amazonaws.com. Here is how you can use it:
https://alami-source-request.amazonaws.com/cgi-bin/source_request.cgi?instance_id=i&region=eu-west-1&version=2011-08-0&srpm_name=stunnel-4.29-3.6.amzn1.src.rpm
Unfortunately you need to know the exact package name. The version is as it's in the get_reference_source script. And it seems there is no validation done on instance_id.
The above URL will return another URL with an access key, where you can download the SRPM for a limited time. After that you have to generate another URL with the above source_request.cgi.
Look for Accessing Source Packages for Reference in
http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/AmazonLinuxAMIBasics.htm

Resources