Created
May 1, 2012 16:14
-
-
Save dayglojesus/2569267 to your computer and use it in GitHub Desktop.
Puppet Type/Provider: Simple
This file contains 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
# Simple Provider | |
require 'fileutils' | |
Puppet::Type.type(:simple).provide(:simple) do | |
desc "Provides simple useless file creation" | |
def create | |
notice("Creating: #{resource[:name]}") | |
system('/usr/bin/touch', "#{resource[:path]}/#{resource[:name]}") | |
end | |
def destroy | |
notice("Destroying: #{resource[:name]}") | |
system("/bin/rm", "#{resource[:path]}/#{resource[:name]}") | |
end | |
def exists? | |
notice("Checking for existence of: #{resource[:name]}") | |
File.exists?("#{resource[:path]}/#{resource[:name]}") | |
end | |
end |
This file contains 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
# simple.pp | |
simple { 'some_useless_file': | |
path => '/tmp', | |
ensure => 'present', | |
} |
This file contains 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
# Simple Type | |
Puppet::Type.newtype(:simple) do | |
@doc = "Create useless files for demonstration" | |
ensurable | |
newparam(:name) do | |
desc "Name of the file to create" | |
isnamevar | |
end | |
newparam(:path) do | |
desc "Path at which to create the file" | |
end | |
end |
You can also use Puppet::Util::Execute rather than system directly and get exception handling and a lot more, although it does look correct to use touch/unlink in this case.
What is the difference between Puppet::Util::Execute and declaring something like this...
commands :touch => '/usr/bin/touch'
In the provider? Is it functionally equivalent?
…On 2012-05-02, at 7:42 PM, Luke Kanies wrote:
You can also use Puppet::Util::Execute rather than system directly and get exception handling and a lot more, although it does look correct to use touch/unlink in this case.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2569267
Using 'commands' is much better, actually - you get automatic validation of the provider (e.g., the provider fails if commands are missing, and you can run tests to determine if the provider is functional).
You're right, actually, that using 'execute' should be very rare.
On May 3, 2012, at 8:04 AM, Brian Warsing wrote:
What is the difference between Puppet::Util::Execute and declaring something like this...
commands :touch => '/usr/bin/touch'
In the provider? Is it functionally equivalent?
On 2012-05-02, at 7:42 PM, Luke Kanies wrote:
> You can also use Puppet::Util::Execute rather than system directly and get exception handling and a lot more, although it does look correct to use touch/unlink in this case.
> ---
>
> Reply to this email directly or view it on GitHub:
> https://gist.github.com/2569267
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2569267
##
Luke Kanies | http://about.me/lak | http://puppetlabs.com/ | +1-615-594-8199
Thanks for the tip.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Noted. Thanks.