configure

in chef/cookbooks/cpe_chefclient/resources/cpe_chefctl.rb [33:67]


  def configure
    configs = node['cpe_chefclient']['config'].to_hash
    configs_to_manage = []
    chef_path = node['cpe_chefclient']['path']
    chef_run_list = node['cpe_chefclient']['run_list'].to_hash
    configs.each do |conf_name, conf|
      chef =  conf.key?('chef') ? conf['chef'].compact : {}
      ohai = conf.key?('ohai') ? conf['ohai'].compact : {}
      
      next if chef.empty? && ohai.empty?

      config_path = ::File.join(
        chef_path,
        "#{conf_name}.rb",
      )
      
      template config_path do
        source 'client.rb.erb'
        variables(
          'chef' => chef,
          'ohai' => ohai,
        )
      end
      configs_to_manage << config_path
    end
    config_json = ::File.join(chef_path, '.cpe_chefclient.json')
    cleanup(configs_to_manage, config_json)
    update_json_file(configs_to_manage, config_json)
    
    unless chef_run_list.nil? || chef_run_list.empty?
      run_list_json = ::File.join(chef_path, 'run-list.json')
      update_json_file(chef_run_list, run_list_json)
    end
  end