Last active
August 29, 2015 14:20
-
-
Save acidprime/729a38031e9aeaa6d525 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/opt/puppet/bin/ruby | |
require 'puppet' | |
require 'r10k/deployment/environment' | |
Puppet.parse_config | |
keyscan = `ssh-keyscan github.com 2>/dev/null`.split | |
FileUtils.mkdir_p('/root/.ssh/') | |
FileUtils.touch('/root/.ssh/known_hosts') | |
sshkey = Puppet::Resource.new('sshkey', keyscan[0], :parameters => { | |
:ensure =>'present', | |
:target => "/root/.ssh/known_hosts", | |
:type => keyscan[1], | |
:key => keyscan[2], | |
}) | |
result, report = Puppet::Resource.indirection.save(sshkey) | |
environment = R10K::Environment::Git.new( | |
Puppet[:environment], | |
Puppet.settings[:environmentpath], | |
Puppet[:environment], | |
{ | |
:remote => Dir.pwd, | |
:ref => Puppet[:environment], | |
} | |
) | |
environment.sync | |
puppetfile = environment.puppetfile | |
puppetfile.load! | |
puppetfile.modules.each do |mod| | |
mod.sync | |
end |
adrienthebo
commented
Apr 29, 2015
class KickEnv
include R10K::Action::Visitor
def initialize(environment)
@environment = environment
end
def call
@environment.accept(self)
end
private
def visit_environment(env)
env.sync
yield
end
def visit_puppetfile(pf)
pf.load!
yield
pf.purge # if you want to wipe out old modules
end
def visit_module(mod)
mod.sync
end
end
environment = R10K::Deployment::Environment.new(Puppet[:environment], Dir.pwd, Puppet.settings[:environmentpath])
kicker = KickEnv.new(environment)
kicker.call
More comments:
R10K::Deployment::Environment
is deprecated. Use R10K::Environment::Git.new
. The order of args was shuffled to be more sane, so make sure you check out https://github.com/puppetlabs/r10k/blob/master/lib/r10k/environment/git.rb#L26-L34
R10K::Environment::Git.new(
Puppet[:environment],
Dir.pwd,
Puppet[:environment], # watch out for environment name normalization; it won't happen automatically here
{
:remote => 'git://github.com/blarghy/mcblarghBLARGH',
:ref => 'WHARRBARGL',
}
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment