Skip to content

Instantly share code, notes, and snippets.

@haani-niyaz
Created February 9, 2015 04:20
Show Gist options
  • Save haani-niyaz/e7f72eda4727e9190084 to your computer and use it in GitHub Desktop.
Save haani-niyaz/e7f72eda4727e9190084 to your computer and use it in GitHub Desktop.
Ruby script to update yaml config value via command-line variable
# call script with:
# ruby scriptname.rb hieravar=value
require 'yaml'
# Get value to change hieravar=value
arg = ARGV[0].split('=')
field_name = arg[0]
field_value = arg[1]
# Dictionary
hiera = YAML.load_file('source.yaml')
# Debug
puts hiera.inspect
# Update value
hiera[field_name] = field_value
# Write new data to file
File.open('source.yaml','w') do |h|
h.write hiera.to_yaml
end
# Debug
puts hiera['my_value']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment