Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Puppet is a declarative language, and it should be used to describe 'this should be like this'. Other than execs (which are given the onlyif/unless/creates option to help you make them idempotent, which has the side effect of being able to conditionally do things on the system) your only option is to either create your own custom resource, or use a custom facter fact.

The generate function runs on your puppet master, not on the agent. That is only a possible 'workaround' if you are running 'masterless' puppet, with puppet apply on your nodes.

If you need to react to how something is, the best course of action is to create a custom fact that checks for the existence of the file, and use that value in a conditional to wrap whatever other resource you do or don't want to apply.

something similar to the below like this

# yourmodulename/lib/facter/mycustomfile.rb
require 'facter'

if File.exist? ' /path/to/your/file' #I'm not sure what the ruby syntax is on windows, try it out in irb first
  Facter.add(:powershell_exists) do
    setcode do
      true
    end
  end
end

Also, I don't know if this will help you, but have you looked at https://forge.puppet.com/puppetlabs/powershell ?

Puppet is a declarative language, and it should be used to describe 'this should be like this'. Other than execs (which are given the onlyif/unless/creates option to help you make them idempotent, which has the side effect of being able to conditionally do things on the system) your only option is to either create your own custom resource, or use a custom facter fact.

The generate function runs on your puppet master, not on the agent. That is only a possible 'workaround' if you are running 'masterless' puppet, with puppet apply on your nodes.

If you need to react to how something is, the best course of action is to create a custom fact that checks for the existence of the file, and use that value in a conditional to wrap whatever other resource you do or don't want to apply.

something similar to the below like this

# yourmodulename/lib/facter/mycustomfile.rb
require 'facter'

if File.exist? ' /path/to/your/file' '/path/to/your/file' #I'm not sure what the ruby syntax is on windows, try it out in irb first
  Facter.add(:powershell_exists) do
    setcode do
      true
    end
  end
end

Also, I don't know if this will help you, but have you looked at https://forge.puppet.com/puppetlabs/powershell ?