-
-
Save dayglojesus/2569267 to your computer and use it in GitHub Desktop.
# 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 |
# simple.pp | |
simple { 'some_useless_file': | |
path => '/tmp', | |
ensure => 'present', | |
} |
# 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 |
Running a puppet agent -t
the first time produces the expected result. However, subsequent execs of puppet agent -t
produce...
info: Caching catalog for some.host.com info: Applying configuration version '1335888340' err: /Stage[main]//Node[van-daphne.ucs.sfu.ca]/Simple[a_useless_file]: Could not evaluate: No ability to determine if simple exists notice: Finished catalog run in 0.08 seconds
Everytime. No matter how times I reboot the server or client, I get the same result -- apply once, fail thereafter.
If I purge /var/lib/puppet
, puppet agent will again run again without error, but (again) ONLY ONCE!
My 2p: Try not to use system() from a provider unless you absolutely have to (each new fork() == a pain). In other words, provided that you have already required FileUtils, I do recommend you use FileUtils#touch and FileUtils#remove (or File#unlink) :)
Noted. Thanks.
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.
Thanks for the tip.
NOTE: The file names listed here have their respective directory appended to the original name as "directory_" to avoid Gist conflict.
Master: Puppet 2.7.11 on Ubuntu 11.04
Client: Puppet 2.7.11 on Mac OS X 10.7.2