Puppet type provider help?

14 views
Skip to first unread message

Jason McMahan

unread,
Apr 4, 2018, 5:09:32 PM4/4/18
to Puppet Users
Good day, 
I am reviewing a type and provider and would like input or help to better understand.

The provider is 
require 'puppet/util'
Puppet::Type.type(:winad_group).provide(:powershell) do
    confine :operatingsystem => :windows
    defaultfor :operatingsystem => :windows

    commands :powershell => Puppet::Util::Powershell.getPowershellCommand

The type is 
Puppet::Type.newtype(:winad_group) do

Then lastly there is a file /puppet/util/powershell.rb
class Powershell
  def self.getPowershellCommand()
    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
  end
end

If i copy the syntax 
    commands :powershell => 
    if File.exist?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe")
      "#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe"
    elsif File.exist?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe")
      "#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe"
    else
      'powershell.exe'
    end

Into my provider i am able to run the command correctly, why can i not autoload the powershell.rb file and properly use it across multiple providers?

Thank you for any help.

Josh Cooper

unread,
Apr 4, 2018, 5:47:47 PM4/4/18
to puppet...@googlegroups.com
Not sure what's the issue is... but could you use the powershell module instead https://github.com/puppetlabs/puppetlabs-powershell?

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/dc8c6918-683d-4d1f-ae2c-b94761c79239%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Josh Cooper | Software Engineer

Jason McMahan

unread,
Apr 6, 2018, 11:12:47 AM4/6/18
to Puppet Users
Thank you for the Reply Josh,
I am new to working with types and providers. 

This module is me trying to learn because winad module is something we really need.

I was thinking if i could tell the winad module to use powershell module for its commands that would be great but i am not sure how to do that.

The module i am trying to get working for us is https://forge.puppet.com/shoneslab/winad

Any help or directions is greatly appreciated.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages