Skip to content

Instantly share code, notes, and snippets.

@stormsilver
Created October 28, 2009 15:28
Show Gist options
  • Save stormsilver/220541 to your computer and use it in GitHub Desktop.
Save stormsilver/220541 to your computer and use it in GitHub Desktop.
default[:networking][:static_hosts] = {}
# read the existing hosts file on first run and preserve any entries found there
f = File.new("/etc/hosts")
static_hosts = {}
f.each_line do |line|
# ...
static_hosts[ip] = hostname
# ...
end
f.close
# preserve any attributes were here before
# self refers to a node object, which is the context in which this file is evaulated
(self[:networking][:static_hosts]).each do |ip, hostname|
# ...
static_hosts[ip] = hostname
# ...
end
# unequivocally set the attribute
set[:networking][:static_hosts] = static_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment