chef-client error: Errno::ENOENT: No such file or directory @ rb_sysopen - /etc/chef/chef_guid

1.6k views Asked by At

We are using test kitchen to test our chef cookbooks.

On running chef-client inside the kitchen container, I am seeing this error:

[2020-03-21T07:22:21+00:00] WARN: *****************************************
[2020-03-21T07:22:21+00:00] WARN: Did not find config file: /etc/chef/client.rb, using command line options.
[2020-03-21T07:22:21+00:00] WARN: *****************************************
Starting Chef Client, version 14.2.0

Running handlers:
[2020-03-21T07:22:23+00:00] ERROR: Running exception handlers
Running handlers complete
[2020-03-21T07:22:23+00:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated in 01 seconds
[2020-03-21T07:22:23+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2020-03-21T07:22:23+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2020-03-21T07:22:23+00:00] FATAL: Errno::ENOENT: No such file or directory @ rb_sysopen - /etc/chef/chef_guid

I have already run

$ kitchen create
$ kitchen converge

on the host.

On the kitchen VM, the directory /etc/chef doesn't exist.

[root@kitchen-test ~]# ls /etc/chef
ls: cannot access /etc/chef: No such file or directory

I am trying to run chef-client in trace log level mode as kitchen converge doesn't have trace logging. kitchen converge only supports debug level.

Versions:

Test Kitchen version 2.3.3 (on host) with dokken driver
Chef: 14.2.0 (in kitchen vm)
1

There are 1 answers

0
user674669 On

I have a hacky way to run chef-client in trace mode on the kitchen client node.

While kitchen converge is running, backup the files in /opt/kitchen somewhere safe. I chose /tmp

rync -av /opt/kitchen /tmp/

Kill kitchen converge by doing ^C or let it complete.

The structure of /opt/kitchen should look something like:

[root@node kitchen]# ls -a /tmp/kitchen/
.  ..  cache  chef_guid  client.pem  client.rb  clients  cookbooks  data_bags  dna.json  encrypted_data_bag_secret  environments  nodes  ohai  validation.pem

Now run chef-zero

# /opt/chef/embedded/bin/ruby /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-zero-14.0.6/bin/chef-zero &
(# /opt/chef/embedded/bin/chef-zero & might work too)

Upload everything to chef-zero server

# cd /opt/kitchen
# /opt/chef/embedded/bin/knife upload . --chef-zero-host localhost --chef-zero-port 1 -c client.rb -V

Now run chef-client in trace mode

# /opt/chef/embedded/bin/chef-client -z -l trace -F doc -c /opt/kitchen/client.rb -j /opt/kitchen/dna.json