Created
February 9, 2015 04:20
-
-
Save haani-niyaz/e7f72eda4727e9190084 to your computer and use it in GitHub Desktop.
Ruby script to update yaml config value via command-line variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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