Skip to content

Instantly share code, notes, and snippets.

@popsikle
Created February 19, 2015 14:16
Show Gist options
  • Save popsikle/bd8df3359c186be03fe4 to your computer and use it in GitHub Desktop.
Save popsikle/bd8df3359c186be03fe4 to your computer and use it in GitHub Desktop.
CoreOS vagrant - config.rb snippet to regen token
# init a cluster, if needed
if File.exists?('user-data')
require 'open-uri'
require 'yaml'
data = YAML.load(IO.readlines('user-data')[1..-1].join)
if data['coreos']['etcd']['discovery'].nil? and ARGV[0].eql?('up')
token = open('https://discovery.etcd.io/new?size=3').read
data['coreos']['etcd']['discovery'] = token
yaml = YAML.dump(data)
File.open('user-data', 'w') { |file| file.write("#cloud-config\n\n#{yaml}") }
elsif not data['coreos']['etcd']['discovery'].nil? and ARGV[0].eql?('destroy')
data['coreos']['etcd']['discovery'] = nil
yaml = YAML.dump(data)
File.open('user-data', 'w') { |file| file.write("#cloud-config\n\n#{yaml}") }
end
end
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment