Skip to content

Instantly share code, notes, and snippets.

@dalen
Created September 8, 2013 23:29
Show Gist options
  • Save dalen/6489506 to your computer and use it in GitHub Desktop.
Save dalen/6489506 to your computer and use it in GitHub Desktop.
function to gradually deploy using puppet
module Puppet::Parser::Functions
newfunction(:gradual_deploy, :type => :rvalue, :arity => 4, :doc => "\
Gradually deploy something
Arguments are from, to, start and finish. Will gradually move from returning <from>
to returning <to> over the duration between <start> and <finish>.
start and finish are specified as ruby datetime strings, supports all formats that ruby
can parse.
") do |args|
from, to, start, finish = *args
require 'date'
start = DateTime.parse(start)
finish = DateTime.parse(finish)
# Duration of deploy in seconds
duration = ((finish-start)*86400).to_i
Puppet::Parser::Functions.function('fqdnrand')
if start+(function_fqdnrand(duration).to_r/86400) > DateTime.now then
return to
else
return from
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment