Chef workstation is unable to find knife.rb unless in "chef-repo"

4.5k views Asked by At
  1. When I run knife node list while in /home/ec2-user it complains

    "WARNING: No knife configuration file found
    ERROR: Your private key could not be loaded from /etc/chef/client.pem Check your configuration file and ensure that your private key is readable"

  2. When I run knife node list while in /home/ec2-user/chef-repo it executes successfully
    chef-repo directory contains .chef/knife.rb

My knife.rb is located in /home/ec2-user/chef-repo/.chef/knife.rb

My knife.rb contents:

log_level                :info
log_location             STDOUT
node_name                'admin'
client_key               '/home/ec2-user/chef-repo/.chef/admin.pem'
validation_client_name   'chef-validator'
validation_key           '/home/ec2-user/chef-repo/.chef/chef-validator.pem'
chef_server_url          'https://XX.XX.XX.XX:443'
syntax_check_cache_path  '/home/ec2-user/chef-repo/.chef/syntax_check_cache'
cookbook_path [ '~/chef-repo/cookbooks/cookbooks' ]
1

There are 1 answers

0
Roland On BEST ANSWER

If you want to have a "global per-user" config, either set the KNIFE_HOME environment variable to your .chef directory or copy/symlink your knife.rb to /home/ec2-user/.chef/knife.rb

Specification: https://github.com/chef/chef/blob/master/spec/unit/workstation_config_loader_spec.rb#L51

Implementation: https://github.com/chef/chef/blob/master/lib/chef/workstation_config_loader.rb#L97-L124