How to set windows hostname/FQDN?


I to set hostname for windows. How can I do it.

I have been trying with but confused with the usage.

Please help!!


I am thinking you will want to add this to your run list: recipe[windows-hostname] maybe in from a role file.

Then add your hostname as the attribute set_fqdn.

You can do this by doing something like this:

name  '<Your role file name>'
run_list 'recipe[windows-hostname]'

  set_fqdn: 'hostname.domainname'

Then you can upload your role file to chef using knife:
knife role from file <path/to/rolefile.rb>
Then add this to your run list:
knife node run_list add <node> 'role[<role file name>]'

Then you should be able to run chef-client on your node and it should set your hostname and restart windows.

I typically use DSC resources for all of my Windows stuff so save me some work. In the case of renaming computers I use the xComputerManagement DSC resource then just use the chef dsc_resource with attributes.

dsc_resource 'RenameComputer' do
  resource :xComputer
  property :Name, node['windows']['computer_name']

I should note that the dsc_resource requires WMF5. If you are using WMF4 still then you need to use the dsc_script resource.

1 Like

Hi Gator, I am curious about how you handle the reboot in that scenario?

Alex, there is a DSC resource, xPendingReboot, to handle pending reboots which I use if I am using straight DSC.

However, in Chef I have had more success using the built-in Chef resource for reboots and only execute it if the DSC resources was executed. Such as:

reboot 'Reboot after rename computer' do
  reason 'The computer was renamed'
  subscribes :reboot_now, 'dsc_resource[RenameComputer]', :immediately
1 Like