Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is there an onlyif condition that can apply to a Puppet class or to a "file" command in a manifest?

I am using CentOS 7 with Puppet Enterprise 4.4.x for my Puppet Master. I am using Windows Server 2012 with Puppet Enterprise 4.x for my Puppet Agents.

My goal is to have a class in a Puppet Manifest apply conditionally to each Windows Server depending on whether or not a file is present.

Is there an onlyif condition that can apply to a Puppet class or to a file command?

Here is what I am trying:

I know how to use generate in a Puppet manifest when the Puppet Agent node is Linux. I do not know how to use it with Windows. When I try it, with either batch commands or PowerShell commands to test the existence of a file, I get an error with the Puppet Agent runs on the Windows Server. The error says "Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at '=>' at ...line 86..."

I have tried a variety of different syntax with the generate command. I want to assign a variable to the output of a command that would run on the Puppet Agent node.

$vari = generate('C:\\WindowsPowerShell\\powershell.exe if(test-path ...)')

I have tried to not use the generate command and assign a variable too.

$vari = if(test-path ...)

Nothing seems to work. It seems that my conditional logic will have to be applied to every file command in the manifest. The exec commands can use the onlyif clause that I created. It would be more maintainable to have the class that has a variety of different commands execute based on the Puppet Agent node having a specific file.

I have tried to get a variable from reading a file on the Puppet Agent node. This failed for different reasons. I don't know how to make a file command (or a class of different files) in Puppet be activate conditionally. Also, I want the Puppet manifest with the class (of exec and file commands) to remain in one file. What should I do?