Ask Your Question

Exit from the puppet code if powershell 'if' condition returns true

asked 2018-05-15 23:08:34 -0600

Daizy gravatar image

I have written a puppet manifest where I have written the command to be executed using powershell provider. The application installation file is already present in C:\Users\test\ directory. This command has to check that if .msi file is already present in C:\temp\uipath\ directory, exit the code, else copy the files from C:\Users\test\ to C:\temp\uipath\. And then some other puppet loops are there after this to install the application and so on.

exec {'CheckFileExists11':
                provider => powershell,
                command     => 'if ( Test-Path C:\temp\uipath\UiPathStudio-2018.1.msi){ exit } else {cp C:\Users\test\* C:\temp\uipath\}',

But here, if the file is already present in uipath directory, its just exiting from the powershell and not from the puppet manifest. I want to exit from the puppet manifest script if the file is already present in C:\temp\uipath. Can I get a suggestion on this?

edit retag flag offensive close merge delete


Obviously, you're attempting to use the wrong to tool to achieve the wrong task, but the approach would be something like: Create a custom fact checking for the file's existence, and then – based on the fact – provoke a catalog error utilizing the fail() function.

Kai Burghardt gravatar imageKai Burghardt ( 2018-05-16 09:46:09 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-05-18 17:52:18 -0600

binford2k gravatar image

Instead of writing logic, just define the state you want. This code will do exactly what you want. If and only if the file doesn't exist where you want it, then it will copy it from the source. Puppet is not a one-shot, fire-and-forget scripting language. It is a modeling language (like a blueprint) that helps you define state, meaning that it doesn't matter if you run it again.

file { 'C:\temp\uipath\the_name_of_the_installer.msi':
    ensure => present,
    source => 'C:\ Users\test\the_name_of_the_installer.msi',
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-05-15 23:08:34 -0600

Seen: 92 times

Last updated: May 18