I have the following bit of code in my cookbook:
if File.file?('/etc/test.yml') config = YAML.load(File.read('/etc/test.yml')) else config = Hash.new end config['key'] = node['test']['license'] config['verbose'] = 0 config['sample_rate'] = 120 file '/etc/test.yml' do content config.to_yaml end
My code works in that the .yml file will be created if it doesn’t already exist and will populate the file with three variables when creating the .yml file. But what I’m attempting to add to this bit of code is to confirm if the .yml file already exists that these three variables also exist in the .yml file. I’ll need to add a check to each config[‘variable’] = line confirm if this variable exists and if the variable is missing to add the variable to the .yml file.
Any advice on the code required to achieve this would be greatly appreciated.