I have the following Question and got redirected here from Github, so I hope you can help me.
Is it possible to obtain the Chef::Client instance in a running recipe?
I am using the following versions of Chef under CentOS 7
What I want to achieve is a chef-server switch during the chef-client run.
Scenario is that I am installing a VM with chef-zero. During the chef-run a chef server is installed and the cookbooks/nodes/data bags/etc. are uploaded to the fresh server. Then I want the running client to report its results to the server.
What I did is creating the required files (org-val cert, client.rb, etc.) and then trigger a
Chef::Config.from_file('/etc/chef/client.rb') and the running client would contact the chef-server to report at the end of the current run.
While reporting it receives
Net::HTTPServerException: 401 "Unauthorized" because there is no client on the server, just the node.
So I tried to do a
node.save in the hope it would create a client and then downloading the acl with knife, fixing it and uploading it again. Unfortunately
node.save does not seem to try and create a client if it doesn’t exist.
What I would like to do now is invoke
Chef::Client.register() instead of
node.save but it seems that there is no way for a recipe to get the instance of the running chef-client.