Unable to add cookbook dependency in metadata.rb chef - ruby

I am trying to include my abc-cookbook which has a ruby service installed in metadata.rb of another cookbook (say xyz-cookbook) which i have to launch.
But while deploying the instance in opswork my setup is failing with an error as :
STDERR: Unable to satisfy constraints on package abc-cookbook, which does not exist, due to solution constraint (xyz-cookbook = 0.1.0). Solution constraints that may result in a constraint on abc-cookbook: [(xyz-cookbook = 0.1.0) -> (abc-cookbook >= 0.0.0)]
Missing artifacts: abac-cookbook
Demand that cannot be met: (xyz-cookbook = 0.1.0)
Unable to find a solution for demands: activemq (1.3.3), apacheds (0.1.0), apt (
---- End output of /opt/aws/opsworks/local/bin/berks vendor /opt/aws/opsworks/current/berkshelf-cookbooks ----
Ran /opt/aws/opsworks/local/bin/berks vendor /opt/aws/opsworks/current/berkshelf-cookbooks returned 106
Cookbook Trace:
---------------
/var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_commons/libraries/shellout.rb:9:in `shellout'
/var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_berkshelf/providers/runner.rb:13:in `block (3 levels) in class_from_file'
Resource Declaration:
---------------------
# In /var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_berkshelf/providers/runner.rb
11: ruby_block 'Install the cookbooks specified in the Berksfile and their dependencies' do
12: block do
13: Chef::Log.info OpsWorks::ShellOut.shellout(
14: berks_install_command,
15: :cwd => ::File.dirname(OpsWorks::Berkshelf.berksfile),
16: :environment => {
17: "BERKSHELF_PATH" => Opsworks::InstanceAgent::Environment.berkshelf_cache_path,
18: "LC_ALL" => "en_US.UTF-8"
19: }
20: )
21:
22: ::FileUtils.rm_rf Opsworks::InstanceAgent::Environment.berkshelf_cache_path
23: end
24:
25: only_if do
26: OpsWorks::Berkshelf.berkshelf_installed? && OpsWorks::Berkshelf.berksfile_available?
27: end
28: end
29: end
Compiled Resource:
------------------
# Declared in /var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_berkshelf/providers/runner.rb:11:in `block in class_from_file'
ruby_block("Install the cookbooks specified in the Berksfile and their dependencies") do
action "run"
retries 0
retry_delay 2
block_name "Install the cookbooks specified in the Berksfile and their dependencies"
cookbook_name "opsworks_berkshelf"
block #<Proc:0x0055813e8bcb70#/var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_berkshelf/providers/runner.rb:12>
only_if { #code block }
end
[2016-01-08T12:33:45+00:00] INFO: Running queued delayed notifications before re-raising exception
[2016-01-08T12:33:45+00:00] ERROR: Running exception handlers
[2016-01-08T12:33:45+00:00] ERROR: Exception handlers complete
[2016-01-08T12:33:45+00:00] FATAL: Stacktrace dumped to /var/lib/aws/opsworks/cache.stage1/chef-stacktrace.out
[2016-01-08T12:33:45+00:00] ERROR: ruby_block[Install the cookbooks specified in the Berksfile and their dependencies] (/var/lib/aws/opsworks/cache.stage1/cookbooks/opsworks_berkshelf/providers/runner.rb line 11) had an error: Mixlib::ShellOut::ShellCommandFailed
Also I have added the dependency in xyz-cookbook metadata.rb as :
name 'xyz-cookbook'
maintainer ''
maintainer_email ''
license 'All rights reserved'
description 'Installs/Configures create'
long_description 'Installs/Configures create'
version '0.1.0'
depends 'abc-cookbook'
What am I missing and what is the error actually..

I did resolve this by adding dependency in my root Berksfile, which i missed even though i included my cookbook in another custom cookbook.
This helped me :
Important
Do not declare cookbooks by including a metadata line in your
Berksfile and declaring the cookbook dependencies in metadata.rb. For
this to work correctly, both files must be in the same directory. With
AWS OpsWorks, the Berksfile must be in the repository's root
directory, but metadata.rb files must be in their respective cookbook
directories. You should instead explicitly declare external cookbooks
in the Berksfile

Related

Poise cookbook failing with compilation error

I am getting compile error on poise cookbook . i started to get this error starting yesterday. was there any change done recently ? or do we have fix for this ??
=============================================================================== Recipe Compile Error in
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/libraries/default.rb
ArgumentError
------------- wrong number of arguments (given 2, expected 1)
Cookbook Trace: (most recent call first)
---------------------------------------- /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise/files/halite_gem/poise/helpers/option_collector.rb:98:in
option_collector_attribute' /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise/files/halite_gem/poise/helpers/option_collector.rb:83:in attribute'
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise/files/halite_gem/poise/helpers/template_content.rb:143:in
attribute' /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources/poise_archive.rb:67:in class:Resource'
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources/poise_archive.rb:39:in
<module:PoiseArchive>' /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources/poise_archive.rb:28:in module:Resources'
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources/poise_archive.rb:25:in
<module:PoiseArchive>' /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources/poise_archive.rb:24:in <top (required)>'
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/resources.rb:17:in
<top (required)>' /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/files/halite_gem/poise_archive/cheftie.rb:17:in <top (required)>'
/Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise-archive/libraries/default.rb:19:in
`<top (required)>'
Relevant File Content:
---------------------- /Users/admin/bootstrap/chef/conf/local-mode-cache/cache/cookbooks/poise/files/halite_gem/poise/helpers/option_collector.rb:
91: # #param name [String, Symbol] Name of the attribute to
define. 92: # #param default [Hash] Default value for the
options. 93: # #param parser [Proc, Symbol] Optional parser
method. If a symbol it is 94: # called as a method on
self. Takes a non-hash value and returns a 95: # hash of
its parsed representation. 96: # #param forced_keys
[Array, Set] Method names that will be forced 97:
to be options rather than calls to the parent resource. 98>> def option_collector_attribute(name, default: {}, parser: nil,
forced_keys: Set.new) 99: raise Poise::Error.new("Parser
must be a Proc or Symbol: #{parser.inspect}") if parser &&
!(parser.is_a?(Proc) || parser.is_a?(Symbol)) 100: # Cast
to a set at definition time. 101: forced_keys =
Set.new(forced_keys) unless forced_keys.is_a?(Set) 102: #
Never allow name to be called accidentally since it does really wonky
things. 103: forced_keys.add(:name) 104: #
Unlike LWRPBase.attribute, I don't care about Ruby 1.8. Worlds tiniest
violin. 105: define_method(name.to_sym) do |arg=nil,
&block| 106: iv_sym = :"##{name}" 107:
System Info:
------------ chef_version=17.0.242 platform=mac_os_x platform_version=10.15.4 ruby=ruby 3.0.1p64 (2021-04-05 revision
0fb782ee38) [x86_64-darwin18] program_name=/usr/local/bin//chef-client
executable=/opt/chef/bin/chef-client
The poise-archive cookbook has been deprecated and archived for a long time:
https://github.com/poise/poise-archive
On Chef Infra 17.0 those poise_archive resources should be converted to archive_file resources which do not require an external cookbook:
https://docs.chef.io/resources/archive_file
The poise cookbooks being broken is not a bug which will be fixed.

inspec resources not identified

i am using inspec test framework with ruby for infrastructure testing. I have written a test in the controls
Here is my test:
require 'aws-sdk'
credentials = Aws::AssumeRoleCredentials.new(
role_arn: 'some_value',
role_session_name: 'pipeline')
client_params = {
region: 'ap-southeast-2',
credentials: credentials
}
ec2_client = Aws::EC2::Resource.new(client_params)
instance = ec2_client.instances(filters: [{name:'tag:component', values: ['api', 'fxsnet', 'admin']}])
puts "ec2 Client is : #{ec2_client}"
puts "list of instances based on tag is: #{instance}"
instance.each do |i|
puts 'ID: ' + i.id
puts 'State: ' + i.state.name
#for each of the instance check if tmp file exist
describe file('/tmp') do # The actual test
it { should exist }
end
end
but on execution, i get below error
An error occurred while loading ./inspec-infra-tests/controls/apiInstances.rb.
Failure/Error:
describe file('/tmp') do # The actual test
it { should exist }
end
NoMethodError:
undefined method `file' for main:Object
Did you mean? fail
# ./inspec-infra-tests/controls/apiInstances.rb:46:in `block in <top (required)>'
# ./inspec-infra-tests/controls/apiInstances.rb:35:in `<top (required)>'
No examples found.
0 examples, 0 failures, 0 passed
file InSpec audit resource to test all system file types, including files, directories, symbolic links, named pipes, sockets etc..
#InspecWithRuby #inspec #inspecResourcesNotIdentified #InspecResourcesNotFound
It looks to me like you are attempting to run an inspec test by executing with ruby rather then running with inspec exec. I can reproduce locally by pasting your test in a file:
inspec_example.rb
describe file('/tmp') do # The actual test
it { should exist }
end
Executing with ruby directly
ruby inspec_example.rb gives:
Traceback (most recent call last):
inspec_example.rb:1:in `<main>': undefined method `file' for main:Object (NoMethodError)
Did you mean? fail
Executing with inspec exec works as expected:
inspec exec inspec_example.rb gives:
Profile: tests from inspec_example.rb (tests from inspec_example.rb)
Version: (not specified)
Target: local://
File /tmp
✔ should exist
I'm not familiar with the AWS SDK, but it you want to test for a set of files using InSpec, you can do so like this:
myfiles = %w(temp.err temp.out)
control 'tmp-files-1' do
title 'Test for a set of temp files.'
myfiles.each do |myfile|
describe file('/tmp/' + myfile) do
it { should exist }
end
end
end
If you execute this control, it will return the following (assuming that these files actually exist in your /tmp folder:
✔ tmp-files-1: Test for a set of temp files.
✔ File /tmp/temp.err should exist
✔ File /tmp/temp.out should exist
I'm hoping you can take this example and adapt it to your AWS needs.

api-pagination gem configuration error in Rails 5 when deployed to heroku

I am using the api-pagination gem and deploying to heroku in a rails 5 app. My configuration is ok in development but fails in production. Here is the config file:
config/initializers/api_pagination.rb
ApiPagination.configure do |config|
# If you have both gems included, you can choose a paginator.
config.paginator = :will_paginate
# By default, this is set to 'Total'
config.total_header = 'X-Total'
# By default, this is set to 'Per-Page'
#config.per_page_header = 'X-Per-Page'
# Optional: set this to add a header with the current page number.
#config.page_header = 'X-Page'
# Optional: what parameter should be used to set the page option
config.page_param = :page
# or
config.page_param do |params|
params[:page][:number]
end
# Optional: what parameter should be used to set the per page option
config.per_page_param = :per_page
# or
config.per_page_param do |params|
params[:page][:size]
end
end
Here is the error from the heroku logs:
[INFO ] Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)
[FATAL] NoMethodError (undefined method `[]' for nil:NilClass):
[FATAL] config/initializers/api_pagination.rb:18:in `block (2 levels) in <top (required)>'
The controller action is very simple right now:
def index
listings = Listing.where(active: true)
paginate json: listings
end
I am including no parameters in the route.
In my situation, most of the configuration was unnecessary. I'm not sure why it was causing an error but the defaults for my case are fine, except that I use will_paginate. This is my config file and it works:
ApiPagination.configure do |config|
# If you have both gems included, you can choose a paginator.
config.paginator = :will_paginate
end
If someone follows up with a solution that addresses the error, I will accept it. It might be useful for someone else that requires more of the non-default settings.

Meet "uninitialized constant #<Class:0x8d78f18>::Chef::Resource::CookbookFile" when running chef-client

I am using Chef 11.10.0.
I implement a new resource called MyCookbookFile which inherits Chef::Resource::CookbookFile.
And, I am not going to change the provider this moment (So Chef::Provider::CookbookFile will be used).
require 'chef/resource/cookbook_file'
require 'chef/mixin/securable'
class Chef
class Resource
class MyCookbookFile < Chef::Resource::CookbookFile
include Chef::Mixin::Securable
provides :my_cookbook_file, :on_platforms => :all
# more codes here...
end
end
end
I met the following error:
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/my-cookbook/resources/my_cookbook_file.rb
================================================================================
NameError
---------
uninitialized constant #<Class:0x8d78f18>::Chef::Resource::CookbookFile
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/my-cookbook/resources/my_cookbook_file.rb:6:in `<class:Resource>'
/var/chef/cache/cookbooks/my-cookbook/resources/my_cookbook_file.rb:5:in `<class:Chef>'
/var/chef/cache/cookbooks/my-cookbook/resources/my_cookbook_file.rb:4:in `class_from_file'
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/my-cookbook/resources/my_cookbook_file.rb:
1: require 'chef/resource/cookbook_file'
2: require 'chef/mixin/securable'
3:
4: class Chef
5: class Resource
6>> class MyCookbookFile < Chef::Resource::CookbookFile
Running handlers:
[2014-02-17T08:16:26+00:00] ERROR: Running exception handlers
Running handlers complete
[2014-02-17T08:16:26+00:00] ERROR: Exception handlers complete
[2014-02-17T08:16:26+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 1.189243344 seconds
[2014-02-17T08:16:26+00:00] ERROR: uninitialized constant #<Class:0x8d78f18>::Chef::Resource::CookbookFile
[2014-02-17T08:16:26+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
I tried to print and check the LOAD_PATH in my cookbook. It includes:
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/bin/../lib
And the library should be in place:
[root#localhost /]$ ll /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/resource/cookbook_file.rb
-rw-r--r-- 1 root root 1598 Feb 6 17:22 /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.0/lib/chef/resource/cookbook_file.rb
You should add :: before Chef::Resource::CookbookFile.
class MyCookbookFile < ::Chef::Resource::CookbookFile
And move your my_cookbook_file.rb to libraries folder of the cookbook, since you use pure Ruby and not LWRP syntax.
Change:
class MyCookbookFile < Chef::Resource::CookbookFile
to:
class MyCookbookFile < ::Chef::Resource::CookbookFile

How do you debug opscode chef / ruby errors?

I'm a python guy and struggling to make sense of ruby stacktraces. I'd appreciate if anyone can tell me a systematic method to get to the bottom of what is causing a message like this. Running Opscode 11.4. I thought its probably due to an outdated opscode cookbook, so updated ark to 0.0.17 - the latest. However the problem persists. I thought perhaps it was a dependancy of another cookbook. It is, elasticsearch, however no version is specified. In any case this method seems like guess work however there is not a clear stack trace of where the underlaying problem is. What is the correct way to action such a message?
Synchronizing Cookbooks:
- users
- ark
- elasticsearch
- openssl
- sudo
- yum
- ohai
- munin
- bluepill
- runit
- postgresql
- build-essential
- apt
- git
- nginx
Compiling Cookbooks...
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/ark/libraries/resource_ark.rb
================================================================================
NoMethodError
-------------
undefined method `attribute' for Chef::Resource::Ark:Class
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/ark/libraries/resource_ark.rb:37
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/ark/libraries/resource_ark.rb:
30: #allowed_actions.push(:install, :dump, :cherry_pick, :put, :install_with_make, :configure, :setup_py_build, :setup_py_install, :setup_py)
31: #action = :install
32: #provider = Chef::Provider::Ark
33: end
34:
35: attr_accessor :path, :release_file, :prefix_bin, :prefix_root, :home_dir, :extension, :version
36:
37>> attribute :owner, :kind_of => String, :default => 'root'
38: attribute :group, :kind_of => [String, Fixnum], :default => 0
39: attribute :url, :kind_of => String, :required => true
40: attribute :path, :kind_of => String, :default => nil
41: attribute :full_path, :kind_of => String, :default => nil
42: attribute :append_env_path, :kind_of => [TrueClass, FalseClass], :default => false
43: attribute :checksum, :regex => /^[a-zA-Z0-9]{64}$/, :default => nil
44: attribute :has_binaries, :kind_of => Array, :default => []
45: attribute :creates, :kind_of => String, :default => nil
46: attribute :release_file, :kind_of => String, :default => ''
[2013-02-25T00:19:30+00:00] ERROR: Running exception handlers
[2013-02-25T00:19:30+00:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2013-02-25T00:19:30+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-02-25T00:19:30+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-02-25T00:19:30+00:00] FATAL: NoMethodError: undefined method `attribute' for Chef::Resource::Ark:Class
Seems that the community site version 0.0.17 is not the same as the current head even though they have the same version number. Installing source from github https://github.com/opscode-cookbooks/ark/commit/b8c4aaf17d6e88aa857af6b2038eb0dba9981c0b solved the problem.

Resources