chef / chef-apply

The ad-hoc execution tool for the Chef ecosystem.
https://www.chef.sh/
Apache License 2.0
14 stars 14 forks source link

chef-run fails to converge local cookbooks on remote machine due to possible dependecy issue? #55

Open Ryuzavi opened 5 years ago

Ryuzavi commented 5 years ago

Description

Asked about this issue initially on Chef Slack and was asked to raise an issue here.

I'm trying to run local cookbooks on a remote server with chef-run but it's failing. The issue seems to be dependency related as the chef-run process doesn't appear to be uploading any cookbooks \ recipes \ etc outside of the main recipe (in this case default).

On the remote machine it's created a recipe called cw_recipe that contains the default recipe of the cookbook I'm trying to run but nothing else. So the converge fails straight away as the default recipe attempts to call another recipe in the same cookbook but under the original name.

So pretty weird. I suspect the issue may be that my cookbooks have metadata stored in json format as metadata is mentioned in the stack trace. We also use Berks as the resolver.

Chef Apply Version

chef -v
Chef Workstation: 0.2.35
  chef-run: 0.2.2
  chef-client: 14.7.17
  delivery-cli: master (6862f27aba89109a9630f0b6c6798efec56b4efe)
  berks: 7.0.6
  test-kitchen: 1.23.2
  inspec: 3.0.52

chef-apply -v
Chef: 14.7.17

Platform Version

CentOS Linux release 7.5.1804 (Core)

Replication Case

I guess the recreation is to create a cookbook with metadata stored in json format that has 2 recipes, default and another, and default calls the other through an include_recipe call?

Outside of that our cookbooks are standard affair. This is for my company so I can't upload the cookbooks sadly.

Client Output

[✔] Packaging cookbook... done!
[✔] Generating local policyfile... exporting... done!
[✖] Applying default from /root/chef-repo/cookbooks/run-test/default.rb to target.
└── [✖] [test.localdomain.local] Failed to converge default.

The converge of the remote host failed.

Please examine the log file for a detailed cause of failure.

Stacktrace

[2018-11-27T14:10:53+00:00] ERROR: Error running command [bash -c 'cd /tmp/chef_b9WmgU; chef-client -z --config /tmp/chef_b9WmgU/workstation.rb --recipe-url /tmp/chef_b9WmgU/cw_recipe_policy-fc86cd32b5cfd6659ed296f3a18e8d7f4a95bd6d3e2c5307ca2a38f12021ba6f.tgz']
[2018-11-27T14:10:53+00:00] ERROR: stdout: Starting Chef Client, version 14.7.17
Using policy 'cw_recipe_policy' at revision 'fc86cd32b5cfd6659ed296f3a18e8d7f4a95bd6d3e2c5307ca2a38f12021ba6f'
resolving cookbooks for run list: ["cw_recipe::default@0.0.0 (3eba500)"]
Synchronizing Cookbooks:
  - cw_recipe (0.0.0)
Installing Cookbook Gems:
Compiling Cookbooks...
[2018-11-27T14:10:53+00:00] WARN: MissingCookbookDependency:
Recipe `run-test::create-sudo-user` is not in the run_list, and cookbook 'run-test'
is not a dependency of any cookbook in the run_list.  To load this recipe,
first add a dependency on cookbook 'run-test' in the cookbook you're
including it from in that cookbook's metadata.

================================================================================
Recipe Compile Error in /var/chef-workstation/cache/cookbooks/cw_recipe/recipes/default.rb
================================================================================

Chef::Exceptions::CookbookNotFound
----------------------------------
Cookbook run-test not found. If you're loading run-test from another cookbook, make sure you configure the dependency in your metadata

Cookbook Trace:
---------------
  /var/chef-workstation/cache/cookbooks/cw_recipe/recipes/default.rb:1:in `from_file'

Relevant File Content:
----------------------
/var/chef-workstation/cache/cookbooks/cw_recipe/recipes/default.rb:

  1>> include_recipe 'run-test::create-sudo-user'

System Info:
------------
chef_version=14.7.17
platform=centos
platform_version=7.5.1804
ruby=ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
program_name=/usr/bin/chef-client
executable=/opt/chef/bin/chef-client

Running handlers:
[2018-11-27T14:10:53+00:00] ERROR: Running exception handlers
[2018-11-27T14:10:53+00:00] ERROR: Creating exception report
  - ChefApply::Reporter
Running handlers complete
[2018-11-27T14:10:53+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 04 seconds
[2018-11-27T14:10:53+00:00] FATAL: Stacktrace dumped to /var/chef-workstation/cache/chef-stacktrace.out
[2018-11-27T14:10:53+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2018-11-27T14:10:53+00:00] FATAL: Chef::Exceptions::CookbookNotFound: Cookbook run-test not found. If you're loading run-test from another cookbook, make sure you configure the dependency in your metadata

[2018-11-27T14:10:53+00:00] ERROR: stderr:
[2018-11-27T14:10:53+00:00] ERROR: Remote chef-client error follows:
[2018-11-27T14:10:53+00:00] ERROR: Chef::Exceptions::CookbookNotFound: Cookbook run-test not found. If you're loading run-test from another cookbook, make sure you configure the dependency in your metadata
tyler-ball commented 5 years ago

Thanks for opening this issue @Ryuzavi ! First question: how do you handle cookbook dependencies normally? Do you use Berkshelf? IE, cw_default has a dependency on run-test - do you normally use Berkshelf to look up that dependency and manage versions of it? Or do you use something else?

Ryuzavi commented 5 years ago

Yeah I actually use Berks manually, via berks vendor. I usually do this before I try anything chef (except for kitchen) and do so in this case.

I don't believe I'm explicitly referencing cw_default or run-test directly in my stack as well. It may be a dependent cookbook is I guess?

ericcalabretta commented 4 years ago

This issue is still outstanding. Chef-run seems to fail with any local cookbook dependencies.

chef-run fails if a local cookbook is used, but policyfiles work as expected. Dependencies are okay if they're on the supermarket, but not local.

PS C:\Windows\system32> chef -v
Chef Workstation version: 0.17.5
Chef Infra Client version: 15.8.23
Chef InSpec version: 4.18.100
Chef CLI version: 2.0.0
Test Kitchen version: 2.4.0
Cookstyle version: 5.22.6