Can't modify frozen String


I have the following piece of code in one the recipes?

chef_client_scheduled_task 'Chef Client' do
       user node['chef_client']['task']['user']
       password node['chef_client']['task']['password']
       frequency node['chef_client']['task']['frequency']

and when I run I keep getting

* chef_client_scheduled_task[Chef Client] action add
  Error executing action `add` on resource 'chef_client_scheduled_task[Chef Client]'
  can't modify frozen String

  Resource Declaration:
  # In C:/chef/cache/cookbooks/chef-client/recipes/task.rb

  27: chef_client_scheduled_task 'Chef Client' do
  28:   user node['chef_client']['task']['user']
  29:   password node['chef_client']['task']['password']

I tried changing chef_client_scheduled_task to chef_client_scheduled_task.dup after reading a few blogs but this did not help. Any pointers on how to fix this?


Hmm, I have not changed to Chef 13 yet, but I think you are already using it and this is because of resource cloning, or rather that resource cloning was removed from Chef. The chef-client cookbook already contains a chef_client_scheduled_task 'Chef Client' which means you have to call your resource anything other than Chef Client and it should work.
The error message here is quite misleading. Maybe this will be changed/fixed in future releases of the chef client.


I tried changing C:/chef/cache/cookbooks/chef-client/recipes/task.rb

and chef_client_scheduled_task 'Chef Client' to chef_client_scheduled_task 'ChefC'

everytime I run the recipe this reverts to chef_client_scheduled_task 'Chef Client'. Anything I am missing? I have 13.6.4. Do you recommend downgrading to some 12.x version?


The chef-client cookbook is an official one from the supermarket. You can not just change it and hope that everything works. The thing is that you stated that you have chef_client_scheduled_task 'Chef Client' in one of your recipes. In which recipe is that? Do you want to use this scheduled task from the chef-client cookbook or anything else?


As you noticed in the logs there is task recipe which has this code. There is also a resource in the resources directory scheduled_task.rb

provides :chef_client_scheduled_task

property :user, String, required: true
property :password, String
property :frequency, String, default: 'minute'
property :frequency_modifier, Integer, default: 30
property :start_time, String

action :add do

 # Build command line to pass to cmd.exe
 client_cmd = new_resource.chef_binary_path
 client_cmd << " -L #{::File.join(new_resource.log_directory, 'client.log')}"
 client_cmd << " -c #{::File.join(new_resource.config_directory, 'client.rb')}"
 client_cmd << " -s #{new_resource.splay}"

 # Add custom options
 client_cmd << " #{new_resource.daemon_options.join(' ')}" if 

start_time = new_resource.frequency == 'minute' ? ( + 60 * 
new_resource.frequency_modifier).strftime('%H:%M') : nil
windows_task 'chef-client' do
run_level :highest
command "cmd /c \"#{client_cmd} ^> NUL 2^>^&1\""

user               new_resource.user
password           new_resource.password
frequency          new_resource.frequency.to_sym
frequency_modifier new_resource.frequency_modifier
start_time         new_resource.start_time || start_time


That is an excerpt from the chef-client cookbook and none of your recipes or cookbooks. If you are trying to use the chef-client cookbook then you need to stop trying to modify this cookbook in any way.
Using the cookbook is quite well documented in the README. For example, to use the task recipe of the chef-client cookbook you need to add chef-client::task to the run list for your node and optionally you can tweak it by setting the attributes mentioned in the README.
The preferred was is usually not to just add the cookbook to the run_list but to write a wrapper cookbook:
A good way to start learning all of this is


If I’m reading this conversation right, the error “can’t mosify frozen string” is directly related to the lack of resource cloning in Chef 13.

That’s awesome to know. One of my cookbooks has had that error for a few weeks. Any chance that we could improve that message, so that people like myself wouldn’t have to search too hard?