Trouble with missing attribute in Chef library wrapper cookbook - ruby

I'm wrapping my usage of the Opscode Java cookbook with one for my company.
I've created an attributes\default.rb file with values specific to my usage.
Despite including a value for the windows package, I keep getting the following error:
NoMethodError
-------------
No resource or method named `windows_package' for `Chef::Recipe "windows"'
Here is my attributes\default.rb file:
default[:java][:install_flavor] = "windows"
default[:java][:jdk_version] = "7"
default[:java][:windows][:url] = "http"
default[:java][:windows][:package_name] = "Java VM"
I am certain that I have uploaded the updated cookbook to my server, and I am certain that the attributes in this file are being loaded as I was previously receiving errors about missing the required windows package URL until I added it (path edited out above).

In the windows recipe of the Java cookbook, there is a call to the windows_package provider of the windows Cookbook. Thus, the windows cookbook is required for the Java cookbook at least on your platform.
As the Java cookbook doesn't explicitly depend on the windows cookbook (through the metadata.rb), it fails at this late stage.
The solution is to add the windows cookbook to your run list.

Related

Source for package SQLServer2012SP4KB4018073x64ENU.exe does not exist in chef

i am trying to install sql server 2012 using chef to a virtual box.. Below is the code that i use but i am getting source does not exist error. Below is the server.rb code that i have..
package package_name do
source 'C:\Users\user\AppData\Local\Temp\SQLServer2012SP4KB4018073x64ENU.exe'# package_url
checksum package_checksum
timeout node['sql_server']['server']['installer_timeout']
installer_type :custom
options "/q /ConfigurationFile=#{config_file_path} #{passwords_options}"
action :install
notifies :request_reboot, 'reboot[sql server install]'
returns [0, 42, 127, 3010]
Error
* template[C:\Users\vagrant\AppData\Local\Temp\kitchen\cache\ConfigurationFile.ini] action create (up to date)
windows_package[SQLServer2012SP4KB4018073x64ENU.exe] action install
* Source for package SQLServer2012SP4KB4018073x64ENU.exe does not exist
Aside from making the file accessible for windows_package resource, one more change can be made.
The name of windows_package resource should match the application name displayed in Control Panel. As you are using SQLServer2012SP4KB4018073x64ENU.exe as the name, Chef will start installation of the package every time it is run (which is probably not what we want).
For e.g. if I want to install a simple package like WinSCP, which is displayed in Control Panel as WinSCP <version>, then I should name my resource with that.
windows_package 'WinSCP 5.17.7' do
source 'C:\Users\Administrator\Downloads\WinSCP-5.17.7-Setup.exe'
installer_type :custom
options '/silent'
end
Now if Chef runs again, it will make this install idempotent.

override attributes in elasticsearch cookbook

I am trying to use "elasticsearch/cookbook-elasticsearch" cookbook for with my wrapper cookbook. I want to override following default attributes from cookbook-elasticsearch in my wrapper cookbook.
default.elasticsearch[:rpm_url] = "https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.12.noarch.rpm"
default.elasticsearch[:rpm_sha] = "ab7ea2e00d8f1b73642e3ea44d9647b11e6b0b96"
Cookbook : https://github.com/elasticsearch/cookbook-elasticsearch
How do I do this in my-elasticsearch cookbook ?
cat site-cookbooks/my-elasticsearch/attributes/default.rb
override.elasticsearch[:rpm_url] = "https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.4.noarch.rpm"
override.elasticsearch[:rpm_sha] = "ec8b41c54a6d897479645b2507476e0824bc71db"
is this correct one ?
I want to use this cookbook for chef 10
any help
To add information to #mark-oconnor comment:
Documentation about attributes in chef 10.
Recommended notation would be override['elasticsearch']['rpm_url'] = "new_value" the method and symbol way to access attributes have been problematic in the past.
As the cookbook loading order in chef 10 is not always clearly predictable you have to use override level to ensure the correct value is used when compîling recipes.
Edit after comments:
In the elasticsearch cookbook in version 0.3.13 the default recipe install from tarball.
If you wish to use a packaged install you have to call the corresponding recipe before the default, as in the default recipe there's a guard to not install tarball if elasticsearch is already installed.
The correct recipe in wrapper cookbook for this particular case is:
include_recipe 'elasticsearch::rpm' # Take the overriden attributes and install package
include_recipe 'elasticsearch' # no need to ::default, if omitted it's the recipe loaded

List all the declared packages in chef

I'm working on a infrastructure where some servers don't have access to the internet, so I have to push the packages to the local repo before declaring them to be installed on Chef.
However we've been on a situation where Chef failed to install a package since the package wasn't there on some boxes and it has been successful on some other boxes.
What I want to do is to run a Ruby/RSpec test before applying Chef config on the nodes to make sure the packages declared on the recipes do actually exist on the repo.
In order to do that I need to be able to list all the packages exists in the our recipes.
My question is: Is there anyway to list all the declared packages in Chef? I had a quick look at Chef::Platform and ChefSpec but unfortunately couldn't find anything useful to my problem.
Do you have any idea where is the best place to look at?
If you use ChefSpec you can find all the packages by calling chef_run.find_resources(:package) inside some test. See the source code. Like this:
require 'chefspec'
describe 'example::default' do
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
it 'does something' do
chef_run.find_resources(:package)...
end
end
You could install one or more of the community ohai plugins. For example the following will return information about installed sofware:
debian
Redhat
windows
Once the plugins are enabled they will add additional node attributes that will be searchable from chef-server.

Unable to use application_ruby cookbook with Chef 11.8.0, Cannot find a resource for bundle_options

I have been attempting to setup a chef recipe which installs ruby using RVM and then uses the application_ruby cookbook to configure the application, however I keep running into the error
NameError: Cannot find a resource for bundle_options on ubuntu version 12.04
I am using the following code
application "application setup" do
owner "ubuntu"
group "ubuntu"
repository "https://github.com/me/myapplication.git" // Real address removed
path rails_app_path
revision "master"
rails do
bundler true
precompile_assets true
bundler_deployment true
end
end
I noticed that the bundle_options was recently added, https://github.com/opscode-cookbooks/application_ruby/commit/e7719170a661a957796e8e5d58ba8f4ecd937487 however I am unable to track down if this is causing the issue. I have included
depends "application"
depends "application_ruby"
in my metadata.rb and made sure all my dependencies are installed so I am unsure what I am doing wrong at this point.
According to documentation bundle_options is an attribute of the rails resource, not a resource itself.
The only correct way of using it is INSIDE the "rails" block, so you got the message because you either used it as :
an attribute of the application resource (but outside of the "rails" block)
standalone resource (outside of any resource).
Message you mentioned is being displayed when nonexistent resource is being referenced. e.g. if you had tried to execute following code on your system:
nonexistent_resource "failure gonna happen" do
some_attribute "whatever_value"
end
you would've got a message
NameError: Cannot find a resource for nonexistent_resource on Ubuntu version 12.04
I ran into this problem today as well. It appears the problem is that commit e771917 forgot to add the necessary getter for the bundle_option. Someone filed a PR to fix it (https://github.com/poise/application_ruby/pull/44), but it has not yet been merged. I can confirm that when I made that change locally, this error went away. The forked branch in the PR is located at https://github.com/mauriciosilva/application_ruby/tree/bundle_options_fix.

Deploy java app in Chef cookbook

I am already using application cookbook to deploy and install my java application. I tried it on my own.
application "saymetrix" do
path "/usr/local"
owner "chef"
group "chef"
end
And for the above code i get following error.
Error executing action `deploy` on resource 'application[saymetrix]'
================================================================================
NameError
---------
Cannot find a resource for saymetrix on ubuntu version 12.04
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/application/providers/default.rb:82:in `before_deploy'
/var/chef/cache/cookbooks/application/providers/default.rb:27:in `block in class_from_file'
I don't get how to resolve this?
Refer to the application_java cookbook.
you need to add these in the metadata.rb of your saymatrix cookbook:
depends 'application'
depends 'application_java'
And add necessary details at least including repository and deployment target like tomcat. You can find the section Usage of the example here: application_java

Resources