Reputation: 53
I'm setting up a Chef server for the first time. To test, I've created a Docker instance of Chef (https://hub.docker.com/r/cbuisson/chef-server/), and that successfully runs. I can log in, and I can reach the server from my browser.
However, I am trying to use some "knife" commands on this container, and so far haven't been able to.
MacBook-Pro:chef user1$ knife node list --config ./.chef/config.rb
ERROR: CONFIGURATION ERROR:127.0.0.1 is an invalid chef_server_url. The URL must start with http://, https://, or chefzero://.
MacBook-Pro:chef user1$ cat ./.chef/config.rb
chef_server_url 'https://127.0.0.1/'
MacBook-Pro:chef user1$
Changing the URL in the config file to anything other than 127.0.0.1 still gives this error - as far as I can tell, the --config option doesn't work as described in the documentation, unless I'm seriously misunderstanding something. I haven't been able to find what config file it's reading from, but it's obvious it's not the one I'm specifying with the --config flag.
more troubleshooting:
MacBook-Pro:cookbooks$ echo $KNIFE_HOME
/Users/PERSON/.chef/config.rb
MacBook-Pro:cookbooks$ cat $_
chef_server_url 'https://localhost/organizations/COMPANY'
cookbook_email '[email protected]'
MacBook-Pro:cookbooks $ knife supermarket download hostsfile --config $KNIFE_HOME
ERROR: CONFIGURATION ERROR:127.0.0.1 is an invalid chef_server_url. The URL must start with http://, https://, or chefzero://.
MacBook-Pro:cookbooks$ knife -VV
ERROR: You need to pass a sub-command (e.g., knife SUB-COMMAND)
Usage: knife sub-command (options)
-s, --server-url URL Chef Infra Server URL.
[truncated]
Upvotes: 0
Views: 934
Reputation: 29514
I followed the below to figure which config is being used.
knife -VV
the above command tells me that the C:/opscode/chef-workstation/bin/knife is being used
I went to that specific location and added puts to check it. I verified it by executing knife cookbook upload
Now further drilling down to see where is this error comes from. In the path,
C:\opscode\chef-workstation\embedded\lib\ruby\gems\3.0.0\gems\chef-config-17.9.26\lib\chef-config\config.rb
Search for the method
def self.is_valid_url?(uri)
And modified the line from
url = uri.to_s.strip
to
url = 'https://api.chef.io/organizations/org1'.to_s.strip
which does the magic.
The issue is with the double-quotes("") for the chef_server_url (uri). Modifying the chef_server_url (uri) to be enclosed in single-quotes (''), makes it work. Double-quotes ("") is not evaluating and you can verify the same by adding puts statements for url and uri variables in the method.
Now post changing the uri value, knife commands are working perfectly. And I am able to upload the cookbook as well in the hosted chef.
Upvotes: 0
Reputation: 10102
you did not specify how do you use chef executable - is it via chefdk or via chef rubygem.
my favorite is to use the chef rubygem, see this if the concept is new to you
back to your question, to make sure that your knife configuration file (./.chef/config.rb
) is being read by chef executable, you can place within the configuration file a small probe ruby code that will output once the file is read. place something like the following into your knife configuration:
# .chef/config.rb
puts 'my knife configuration'
now execute the knife command once again and check for the my knife configuration
output. if it isn't there, try repeating it under bundler context as it might solve your pain.
Upvotes: 1