Ok – so it seems the the underlying base classes of my provider are expecting 
the parameters and their validations from the exec type instead of my new type 
– makes sense.  I was able to test that theory out by adding the parameters 
(and in many cases copying the parameters from the exec type) being validated 
to my new type, but that’s not exactly what I was hoping for.  I did get to the 
point where it’s writing out the temp ps1 file and executing, but now I have 
some challenges on the return output.

I was trying to avoid direct execution of calling cmd.exe with powershell and 
re-inventing the wheel because it’s been done so well with the powershell 
provider, and it avoids some of the escape hell with double quotes if trying to 
pass them on the command line.

I’m likely going about this the wrong way (e.g. going overboard) but if anyone 
wants to provide guidance from the realm of sanity, please feel free. 



From: Jim Ficarra 
Sent: Thursday, January 22, 2015 2:24 PM
To: puppet-users@googlegroups.com 
Subject: [Puppet Users] Help with provider inheritance of Josh Cooper's Exec 
PowerShell Provider

I'm as newbie as they come to both Ruby and custom provider development, so 
apologies if I'm missing the obvious up front. :)

I want to write a custom type/provider to manage IIS Settings. I realize that 
there are at least 3 IIS modules in the forge already (and we are using one of 
them) but I am attempting to write my own because 1) I want to learn how to 
write custom providers and not just defined types in Puppet DSL and 2) The 
existing IIS modules don't hit all the granular configurations I need to manage 
so I have a bunch of execs I need to reign in.

That said, the first type/provider I'm playing with is to simply enable and 
disable Logging in IIS at the server and site level.  I am trying to inherit 
from Josh Cooper's Powershell provider because it executes PowerShell, does it 
well:)  

I sometimes see the temp powershell file being written to temp then disappear, 
but it seems I've hit a wall on the exists? method right out of the gate.  When 
I do a puppet run, I get the error:

Error: /Stage[main]/Test_tools/Iis_logging[TestLogging]: Could not evaluate: 
Invalid parameter cwd(:cwd)

Any insight would be appreciated.  Relevant code below.



Running with --trace shows (partial stack trace):
-=-=-=-=-=-=-=-=-=-=-=-=-=
Error: /Stage[main]/Test_tools/Iis_logging[TestLogging]: Could not evaluate: 
Invalid parameter cwd(:cwd)
C:/Tools/Puppet/puppet/lib/puppet/util/errors.rb:97:in `fail'
C:/Tools/Puppet/puppet/lib/puppet/type.rb:618:in `[]'
C:/ProgramData/PuppetLabs/puppet/var/lib/puppet/provider/iis_logging/iis_logging.rb:21:in
 `exists?'
C:/Tools/Puppet/puppet/lib/puppet/property/ensure.rb:81:in `retrieve'
C:/Tools/Puppet/puppet/lib/puppet/type.rb:1035:in `retrieve'
C:/Tools/Puppet/puppet/lib/puppet/type.rb:1063:in `retrieve_resource'
C:/Tools/Puppet/puppet/lib/puppet/transaction/resource_harness.rb:223:in 
`from_resource'
C:/Tools/Puppet/puppet/lib/puppet/transaction/resource_harness.rb:19:in 
`evaluate'
C:/Tools/Puppet/puppet/lib/puppet/transaction.rb:174:in `apply'
C:/Tools/Puppet/puppet/lib/puppet/transaction.rb:187:in `eval_resource'
C:/Tools/Puppet/puppet/lib/puppet/transaction.rb:117:in `call'
C:/Tools/Puppet/puppet/lib/puppet/transaction.rb:117:in `block (2 levels) in 
evaluate'



The resource would be called like this
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

iis_logging {'TestLogging':
   ensure  => present,
   site       => 'applicationhost'
}

Type I've Defined
-=-=-=-=-=-=-=-=-=
Puppet::Type.newtype(:iis_logging) do
desc "Puppet type to set the configuration of IIS Logging"
ensurable
newparam(:site, :namevar => true) do
desc "ApplicationHost for server level or the name of the site"
munge do |value|
value.downcase
end 
end
end


Provider I've Defined (just showing the exists? method - that's the first 
hurdle)
(I've defined (copied) command(:powershell) in this provider because of the 
lack of inheritance of the commands method, but I get the same error with or 
w/out it)
(run method is already redefined in Josh's provider, which is inherited from 
the exec provider - didn't think I need to do antying else)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Puppet::Type.type(:iis_logging).provide(:iis_logging, :parent => 
Puppet::Type.type(:exec).provider(:powershell)) do

commands :powershell =>
    if 
File.exists?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe")
      "#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe"
    elsif 
File.exists?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe")
      "#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe"
    else
      'powershell.exe'
    end
desc "Uses the Exec resource's PowerShell provider to configure IIS Logging 
Parameters"
confine :operatingsystem => :windows
def exists?
                check = false
if resource[:site] == "applicationhost"
pscommand = "Import-Module WebAdministration;(Get-WebConfiguration 
/system.webServer/httpLogging -PSPath IIS:\\).dontLog -eq \$False"
output = run(pscommand, check)
if output.downcase == "true"
return true
else
return false
end
else
pscommand = "Import-Module WebAdministration;(Get-WebConfiguration 
/system.webServer/httpLogging -PSPath IIS:\\ -Location 
#{resource[:site]}).dontLog -eq \$False"
output = run(pscommand, check)
if output.downcase == "true"
return true
else
return false
end
end
end
-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/fc5c3f6f-481d-4f37-a898-ec3d504ecb23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/76BD6B8F777E43D48D91DA1A710601CA%40JimHPPavilionG6.
For more options, visit https://groups.google.com/d/optout.

Reply via email to