I'm getting below error though I added depends 'alphard-python'
in metadata.rb and added to the run list. How do I resolve this dependency error?
Recipe Compile Error in /var/chef/cache/cookbooks/wavefront/recipes/default.rb
NoMethodError
undefined method `depends' for cookbook: wavefront, recipe: default :Chef::Recipe
Cookbook Trace:
/var/chef/cache/cookbooks/wavefront/recipes/default.rb:8:in `from_file'
Relevant File Content:
/var/chef/cache/cookbooks/wavefront/recipes/default.rb:
1: #
2: # Cookbook:: wavefront
3: # Recipe:: install_agent
4: #
5: # Copyright:: 2017, The Authors, All Rights Reserved.
6:
7: require 'mixlib/shellout'
8>> depends 'alphard-python'
9:
10: bash 'Install Wavefront proxy and agent' do
11: cwd Chef::Config[:file_cache_path]
12: code <<-EOH
13: bash -c "$(curl -sL #{node['wavefront']['install_url']})" -- install
14: --proxy
15: --wavefront-url #{node.default['wavefront']['wavefront_url']}
16: --api-token #{node.default['wavefront']['api_token']}
17: --agent \
System Info:
chef_version=15.0.300
platform=centos
platform_version=7.9.2009
ruby=ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
program_name=/bin/chef-client
executable=/opt/chef-workstation/bin/chef-client
depends goes in the metadata.rb file not in a recipe. In the recipe if you want to run a recipe from the dependant cookbook you'd use include_recipe '<cb_name>::<recipe_name>'
within your current recipe.
1 Like
Yeah, I was able to make that change after multiple searches and got through the error. Thank you @Stromweld !
Now, I'm encountering an error during the run of a recipe as below on CentOS 7. I believe apt_package cannot run on CentOS as it's supported only for Ubuntu(Debian) OS. Do you have any suggestions for me to get through this?
Converging 4 resources
Recipe: alphard-python::default
-
apt_package[python] action install[2023-08-17T19:40:57+05:30] INFO: Processing apt_package[python] action install (alphard-python::default line 10)
================================================================================
Error executing action install
on resource 'apt_package[python]'
Errno::ENOENT
No such file or directory - apt-cache
Resource Declaration:
In /var/chef/cache/cookbooks/alphard-python/recipes/default.rb
10: apt_package 'python' do
11: version node['alphard']['python']['version']
12: action :install
13: end
14:
Compiled Resource:
Declared in /var/chef/cache/cookbooks/alphard-python/recipes/default.rb:10:in `from_file'
apt_package("python") do
package_name "python"
action [:install]
default_guard_interpreter :default
declared_type :apt_package
cookbook_name "alphard-python"
recipe_name "default"
version nil
end
System Info:
chef_version=15.0.300
platform=centos
platform_version=7.9.2009
ruby=ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
program_name=/bin/chef-client
executable=/opt/chef-workstation/bin/chef-client
[2023-08-17T19:40:57+05:30] INFO: Running queued delayed notifications before re-raising exception
Running handlers:
[2023-08-17T19:40:57+05:30] ERROR: Running exception handlers
Running handlers complete
[2023-08-17T19:40:57+05:30] ERROR: Exception handlers complete
Chef Infra Client failed. 0 resources updated in 02 seconds
[2023-08-17T19:40:57+05:30] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2023-08-17T19:40:57+05:30] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2023-08-17T19:40:57+05:30] FATAL: Errno::ENOENT: apt_package[python] (alphard-python::default line 10) had an error: Errno::ENOENT: No such file or directory - apt-cache
The error message is saying that the depends method is not defined for the cookbook wavefront. This is because you have not declared the alphard-python cookbook as a dependency in the wavefront cookbook's metadata.rb file.
To resolve this error, open the wavefront cookbook's metadata.rb file and add the following line to the depends section:
depends 'alphard-python'
Once you have saved the metadata.rb file, run berks install to install the alphard-python cookbook. Then, you should be able to run the wavefront cookbook without any errors.
Here are the steps in detail:
1- Open the wavefront cookbook's metadata.rb file.
2- In the depends section, add the following line:
depends 'alphard-python'
3- Save the metadata.rb file.
4- Run berks install to install the alphard-python cookbook.
5- Run the wavefront cookbook.
If you are still getting the error after following these steps, please check the following:
1- Make sure that the alphard-python cookbook is installed on the node.
2- Make sure that the alphard-python cookbook is compatible with the version of Chef you are using.
3- Make sure that the alphard-python cookbook is installed in the correct location.
If you are still having trouble, please post a question on the Chef community forums or Stack Overflow.