0

I am pretty new to Chef. I wanted to install Java on my Chef Nodes through recipes. This is what I tried:

default.rb looks like this:

root@user:/chef-repo/cookbooks/java/recipes#cat default.rb 
        #
        # Cookbook Name:: java
        # Recipe:: default
        #
        # Copyright 2016, YOUR_COMPANY_NAME
        #
        # All rights reserved - Do Not Redistribute
        #

        include_recipe "java"

metadata.rb looks like this:

root@user:~/chef-repo/cookbooks/java# cat metadata.rb 
name             'java'
maintainer       'YOUR_COMPANY_NAME'
maintainer_email 'YOUR_EMAIL'
license          'All rights reserved'
description      'Installs/Configures java'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version          '0.1.0'

depends "java",     "~> 1.39.0"

And then I upload this cookbook by the following command:

root@user:~/chef-repo/cookbooks/java/recipes# knife cookbook upload java
WARN: Ignoring self-dependency in cookbook java, please remove it (in the future this will be fatal).
Uploading java           [0.1.0]
Uploaded 1 cookbook.

Then I log into my Chef-client node and execute this recipe:

root@client:/usr/share/java# sudo chef-client
Starting Chef Client, version 12.11.18
resolving cookbooks for run list: ["java"]
Synchronizing Cookbooks:
  - java (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 0 resources

Running handlers:
Running handlers complete
Chef Client finished, 0/0 resources updated in 02 seconds

It looks like this has not installed anything. I try and check java version and I get nothing.

root@client:~# java -version
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.8-jre-headless
 * openjdk-7-jre-headless
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless
Try: apt-get install <selected package>

Can someone please let me know what am I missing here?

MayankP
  • 23
  • 4
  • `include_recipe "java"` in default.rb file, did you check other recipe is name java, you should write java recipe – Thanh Nguyen Van Jun 14 '16 at 09:54
  • Yes, I checked, recipe name is 'java'. Link is here: https://supermarket.chef.io/cookbooks/java – MayankP Jun 14 '16 at 09:57
  • `knife cookbook list` can you list all cookbooks in chef-server, make sure you have uploaded java cookbook correctly. – Thanh Nguyen Van Jun 14 '16 at 10:26
  • You shouldn't name your cookbook the same as the community cookbook you are trying to work with. Pick a prefix like `foo` and name your cookbook `foo_java` to avoid conflicts. – chicks Jun 14 '16 at 17:58

2 Answers2

3

You have created a cookbook called "java" that depends on another cookbook called "java". I suspect what you're trying to do is consume the community "java" cookbook:

I highly recommend you install Chefdk locally and start using tools like test kitchen to test your cookbook locally and Berkshelf to manage the upload of your cookbook and all its dependencies into your chef server.

The following is an example of installing Java:

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
0

To be a bit more specific than the other answers: you need to rename your wrapper cookbook something like mycompany-java.

coderanger
  • 52,400
  • 4
  • 52
  • 75