Skip to content

Instantly share code, notes, and snippets.

@bodepd
Created July 1, 2015 08:50
Show Gist options
  • Save bodepd/7812c150f68321c57104 to your computer and use it in GitHub Desktop.
Save bodepd/7812c150f68321c57104 to your computer and use it in GitHub Desktop.
ssh_keypair { '/tmp/foo':
ensure => present,
key_type => 'dsa',
}
# /etc/puppet/modules/<module_name>lib/puppet/type/ssh_keypair.rb
Puppet::Type.newtype(:ssh_keypair) do
newparam(:name, :namevar => true) do
validate do |x|
unless x =~ /^\//
fail("Invalid filename #{x}, must be absolute path")
end
end
end
ensurable
newproperty(:key_type) do
newvalues('rsa', 'dsa')
end
# validate do
# end
end
# /etc/puppet/modules/<module_name>lib/puppet/provider/ssh_keypair/default.rb
Puppet::Type.type(:ssh_keypair).provide(
:default,
) do
def create
File.open(resource[:name], 'w') do |fh|
fh.puts(resource[:key_type])
end
end
# def destroy
# def exists?
def exists?
File.exists?(resource[:name])
end
def key_type
File.read(resource[:name])
end
def key_type=(value)
File.open(resource[:name], 'w') do |fh|
fh.write(resource[:key_type])
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment