On Sunday, November 3, 2013 10:46:16 AM UTC-6, Ken Netherland wrote:
>
> Can someone please explain the logic here?
>
> The Puppet documentation says the following:
>
> If this parameter is set, then this exec will run unless the command 
> returns 0
>
> So in the following if Windows Feature is installed, PS returns 1, meaning 
> it will execute, correct?  
>
> exec
> { 
> 'Install-Application-Server':
> command   => 'import-module servermanager; Add-WindowsFeature 
> Application-Server -Restart',
> unless  => 'if ((get-windowsfeature -name Application-Server).Installed) 
> { exit 1 }',
> provider  => powershell,
> }
>
> Is this a Windows related anomaly or am I missing something?
>
>

I guess you're missing something.  The logic is the same on Windows as on 
any other platform Puppet supports.  The standard convention on Windows, 
Linux, OS X, and many other operating systems is that programs return exit 
code 0 to their parent process when they finish successfully, and nonzero 
otherwise.  Thus on Linux, the program /bin/true does nothing but return 
exit code 0.

The Windows (standard) shell, and DOS before it, attempt to make this more 
intuitive by referring to the most recent program's exit code via the 
%errorlevel% variable, so %errorlevel% == 0 means "no error" in that 
environment.

Note that Puppet issue 8083 should not affect you in the case that the 
Application-Server feature is installed, but it is unclear (to a 
non-initiate in Powershell) what the exit code of that 'unless' command 
will be in the alternative case.  It would be better to explicitly "exit 0" 
whenever you do not "exit 1".


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/668a135f-2c98-4f4a-8dde-11e6d64b0157%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to