Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chef-client -z fails when $HOME variable is not set #8673

Open
keigo-brook opened this issue Jun 19, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@keigo-brook
Copy link

commented Jun 19, 2019

Description

chef-client -z fails when $HOME variable is not set.
I encountered this error when I am deploying an instance of Amazon EC2 by AWS CLI, using user-data. (cf. https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html)
This error occurs because $HOME variable is not set when AWS execute user-data scripts.

It seems this bug is fixed for years ago ( #1494 and #3153), but current stable release has same error. I think this error happening the similar cause.

Chef Version

Chef Development Kit 4.0.60

Platform Version

Ubuntu 16.04

Replication Case

Note: I wrote and executed this replication case in my local machine, But when I run these scripts using AWS CLI, I put these in one shell file.

  1. Install ChefDK
$ wget https://packages.chef.io/files/stable/chefdk/4.0.60/debian/9/chefdk_4.0.60-1_amd64.deb
$ sudo dpkg -i ./chefdk_4.0.60-1_amd64.deb
  1. Create simple recipes
$ cat ./chef/config.json
{
	"run_list": [
		"recipe[hello]"
	]
}
$ cat ./chef/cookbooks/hello/recipes/default.rb
log "Hello, Chef!"
  1. unset $HOME
$ sudo su
# unset HOME
# echo $HOME

  1. Run chef-client
# chef-client -z -j config.json
[2019-06-19T11:56:25+00:00] WARN: No config file found or specified on command line. Using command line options instead.
Starting Chef Infra Client, version 15.0.300
resolving cookbooks for run list: ["hello"]
Synchronizing Cookbooks:
  - hello (0.0.0)
Installing Cookbook Gems:

Running handlers:
[2019-06-19T11:56:27+00:00] ERROR: Running exception handlers
Running handlers complete
[2019-06-19T11:56:27+00:00] ERROR: Exception handlers complete
Chef Infra Client failed. 0 resources updated in 01 seconds
[2019-06-19T11:56:27+00:00] FATAL: Stacktrace dumped to /.chef/local-mode-cache/cache/chef-stacktrace.out
[2019-06-19T11:56:27+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2019-06-19T11:56:27+00:00] FATAL: ArgumentError: different prefix: "/" and ".chef/local-mode-cache/cache/cookbooks/hello"

Stacktrace

# cat /.chef/local-mode-cache/cache/chef-stacktrace.out
Generated at 2019-06-19 11:56:27 +0000
ArgumentError: different prefix: "/" and ".chef/local-mode-cache/cache/cookbooks/hello"
/opt/chefdk/embedded/lib/ruby/2.6.0/pathname.rb:522:in `relative_path_from'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-config-15.0.300/lib/chef-config/path_helper.rb:172:in `relative_path_from'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_manifest.rb:270:in `block in parse_file_from_root_paths'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_manifest.rb:269:in `each'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_manifest.rb:269:in `parse_file_from_root_paths'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_manifest.rb:236:in `block in generate_manifest'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_manifest.rb:233:in `each'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_manifest.rb:233:in `generate_manifest'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_manifest.rb:104:in `manifest'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_manifest.rb:175:in `files_for'
/opt/chefdk/embedded/lib/ruby/2.6.0/forwardable.rb:230:in `files_for'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/cookbook_version.rb:204:in `segment_filenames'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/run_context/cookbook_compiler.rb:316:in `block in count_files_by_segment'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/run_context/cookbook_compiler.rb:315:in `each'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/run_context/cookbook_compiler.rb:315:in `inject'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/run_context/cookbook_compiler.rb:315:in `count_files_by_segment'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/run_context/cookbook_compiler.rb:101:in `compile_libraries'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/run_context/cookbook_compiler.rb:74:in `compile'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/run_context.rb:212:in `load'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/policy_builder/expand_node_object.rb:103:in `setup_run_context'
/opt/chefdk/embedded/lib/ruby/2.6.0/forwardable.rb:230:in `setup_run_context'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/client.rb:488:in `setup_run_context'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/client.rb:285:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/application.rb:314:in `run_with_graceful_exit_option'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/application.rb:290:in `block in run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/local_mode.rb:41:in `with_server_connectivity'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/application.rb:273:in `run_chef_client'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/application/client.rb:447:in `run_application'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-15.0.300/lib/chef/application.rb:69:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.6.0/gems/chef-bin-15.0.300/bin/chef-client:25:in `<top (required)>'
/usr/bin/chef-client:316:in `load'
/usr/bin/chef-client:316:in `<main>'
@lneva-fastly

This comment has been minimized.

Copy link

commented Jun 27, 2019

I was able to reproduce this on chef 14.11.21-1. My chef-client -z run works fine in 14.8.12-1 but breaks in 14.11.21.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.