chef-infraknife

Chef Update chef_server_url at 'client.rb' using recipe after Chef Server migration


I want to move my old Chef server to new server and I already succeed to backup the server and restore it to the new server and I migrated 1 computer successfully (manually edited the chef_server_url at client.rb).

Because I have a lot of computers managed by the old Chef Server I need a scalable way to update the client.rb of the computers managed by this server and update the chef_server_url to the new url

My client.rb looks like this:

`chef_server_url  "https://myfirstdomain:1234"
validation_client_name "chef-validator"
file_cache_path   "c:/chef/cache"
file_backup_path  "c:/chef/backup"
cache_options     ({:path => "c:/chef/cache/checksums", :skip_expires => true})
node_name "mycomp"
log_level        :info
log_location       STDOUT
trusted_certs_dir "c:/chef/trusted_certs"
`

and I need to change it to this:

`chef_server_url  "https://seconddomain:1234"
validation_client_name "chef-validator"
file_cache_path   "c:/chef/cache"
file_backup_path  "c:/chef/backup"
cache_options     ({:path => "c:/chef/cache/checksums", :skip_expires => true})
node_name "mycomp"
log_level        :info
log_location       STDOUT
trusted_certs_dir "c:/chef/trusted_certs"
`

I tried to follow the instructions here: https://getchef.zendesk.com/hc/en-us/articles/206692583-Change-Hostname-of-Chef-Server But I failed to figure out how to do this step:

"If you are using the chef-client cookbook to manage your nodes' client.rb file then you could try just setting the node['chef_client']['server_url'] attribute to the new hostname and test to see if the next chef-client run on a node properly changes the client.rb file AND restarts the chef-client service."


Solution

  • As described in the provided instruction, you need to use chef-client cookbook to apply this method, it can manage client.rb for you. You can upload a recipe to the old server with new server url and run it on all the nodes.

    If you do not want to use it, you may consider running knife winrm with some command which will replace the url.

    I am not sure if there is some kind of sed replacement on windows.