Skip to content

Instantly share code, notes, and snippets.

@masterzen
Created October 29, 2011 10:42
Show Gist options
  • Save masterzen/1324327 to your computer and use it in GitHub Desktop.
Save masterzen/1324327 to your computer and use it in GitHub Desktop.
Puppet Extension Point
AST::VarDef
AST::Variable(file)
AST::Function(basename)
AST::String(...)
scope.setvar('file', scope.function_basename('...'))
VARIABLE(file) EQUALS NAME(basename) LPAREN STRING(...) RPAREN
$file = basename('/var/lib/puppet/ssl/certs/mycert.pem')
module Puppet::Parser::Functions
newfunction(:basename, :type => :rvalue, :doc => <<-EOS
Returns the basename of a full pathname. For instance if called
with '/path/to/myfile.txt' will return 'myfile.txt'.
EOS
) do |args|
raise(Puppet::ParseError, "basename(): Wrong number of arguments given (#{args.size} instead of 1)") if arguments.size != 1
File.basename(args[0])
end
end
# drop this in a module lib/facter/
Facter.add("hardware_platform") do
setcode do
%x{/bin/uname -i}.chomp
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment