Skip to content

Instantly share code, notes, and snippets.

@acidprime
Last active August 29, 2015 14:20
Show Gist options
  • Save acidprime/729a38031e9aeaa6d525 to your computer and use it in GitHub Desktop.
Save acidprime/729a38031e9aeaa6d525 to your computer and use it in GitHub Desktop.
#!/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
Copy link

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