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

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.

Related

Can't make code_ownership and code_teams gems to work

The gems code_teams, code_ownership should allow one to tag files/whole folders by team name but after adding them to my project, running bundle install etc, I still encounter the same error
Passed `nil` into T.must
sample team file (placed in config/teams as advised) is as following
name: Smurfs
owned_globs:
- folder/folder2/**/*
The code where I try to use the info is :
x = CodeOwnership.for_backtrace(e.backtrace)
Turns out the path was not in the format expected.
The path should not end with /*

Chef cookbook: undefined local variable or method

I'm having a problem with a chef cookbook that create several shared filesystems.
This is the fragment that is giving me problems:
sii_share_share "ansible" do
remote_path "//#{ node['sii_base']['utils_storage_account_name'] }.file.core.windows.net/ansible"
local_path "/opt/ansible"
fstype "cifs"
dir_owner "root"
dir_group "sysadmin"
dir_mode "0770"
file_mode "0660"
cifs_credentials_file "/root/.smb.utils.credentials"
end
The error is "undefined local variable or method `local_path' for #<#:0x00000000047b3ed8>"
This error is happening with these versions:
Chef-client: 14.1.12
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
With previous versions (chef-client 13.6 and ruby 2.3.1p112) this is working fine. I'm running these cookbooks in Azure, using the Linux Chef extension.
Have anyone experimented something like this?
Thanks in advance.
It's possible your resource is using deprecated property naming.
Verify that the sii_share_share resource has a property named local_path
If it does then you need to verify that all of the code inside the
resource itself refers to the local_path property using
new_resource.local_path and not local_path. This has been a
pending deprecation that went in to effect with Chef Client 14.
You should always review breaking changes before making the move between major versions of Chef Client. The end of each chef-client run also outputs deprecation messages as a warning before these breaking changes go in to place.

Puppet: generate statement fails when trying to retrieve default path of an executable

I have built a stanza to remove a ruby gem package from our servers. The problem is that the ruby gem executable is installed in different paths on the servers, so on one server it could be in /opt/ruby/bin/gem on other servers it's in /usr/local/rvm/rubies/ruby-2.0.0-p353/bin/gem
My stanza uses the generate function in puppet to pull out the default ruby gem installation as follows:
$ruby_gem_location = generate('which', 'gem')
exec { "remove-remote_syslog":
command => "gem uninstall remote_syslog",
path => "$ruby_gem_location:/opt/ruby/bin:/usr/bin:/usr/sbin",
onlyif => "$ruby_gem_location list|grep remote_syslog"
}
When I run puppet agent I get the following error:
Generators must be fully qualified at ****redacted*
I have also tried to provide a default path for the which command as follows:
$ruby_gem_location = generate('/usr/bin/which', 'gem')
and now the error says : Could not evaluate: Could not find command '/usr/bin/gem
I checked the target server and the gem command is in
/usr/local/rvm/rubies/ruby-2.0.0-p353/bin/gem
What am I doing wrong?
How can I pull out the default ruby gem location on our servers?
Thank you in advance
Your code
$ruby_gem_location = generate('/usr/bin/which', 'gem')
will generate a full path to your gem command (if it succeeds). From the result you describe, I think it is generating '/usr/bin/gem', which is perhaps a symlink to the real gem command. You are putting that into your command path instead of just the directory part, and that will not be helpful. It is not, however, the source of the error message you report.
The real problem here is that generate(), like all DSL fucntions, runs during catalog building. I infer from your results that you are using a master / agent setup, so generate() is giving you a full path to gem -- evidently /usr/bin/gem -- on the master. Since the whole point is that different servers have gem installed in different places, this is unhelpful. The actual error message arises from an attempt to execute your onlyif command with the wrong path to gem.
Your best way forward is probably to create a custom fact with which each node can report the appropriate location of the gem binary. You can then use that fact's value in your Exec, maybe:
exec { "remove-remote_syslog":
command => "$::ruby_gem_path uninstall remote_syslog",
onlyif => "$::ruby_gem_path list | grep remote_syslog"
}
Note that you don't need a path attribute if you give a complete path to the executable in the first place.
Details on creating the $::ruby_gem_path custom fact depend on a number of factors, and in their full generality they are rather too broad for SO, but PL provides good documentation.

Trouble with missing attribute in Chef library wrapper cookbook

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.

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.

Resources