Issue #11482 has been updated by Josh Cooper.
Status changed from Unreviewed to Needs More Information
Assignee set to Marco Peterseil
I was able to reproduce the problem (I added logoutput => true to the exec
resource) and I see the following:
<pre>
debug: Exec[test](provider=windows): Executing
'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe C:/test.ps1'
debug: Executing 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
C:/test.ps1'
notice: /Stage[main]//Exec[test]/returns: File C:\test.ps1 cannot be loaded
because the execution of scripts is disabled
on this system. Please see "get-help abo
notice: /Stage[main]//Exec[test]/returns: ut_signing" for more details.
notice: /Stage[main]//Exec[test]/returns: At line:1 char:12
notice: /Stage[main]//Exec[test]/returns: + C:/test.ps1 <<<<
notice: /Stage[main]//Exec[test]/returns: + CategoryInfo :
NotSpecified: (:) [], PSSecurityException
notice: /Stage[main]//Exec[test]/returns: + FullyQualifiedErrorId :
RuntimeException
notice: /Stage[main]//Exec[test]/returns:
C:/Ruby187/lib/ruby/site_ruby/1.8/puppet/parameter.rb:165:in `fail'
C:/Ruby187/lib/ruby/site_ruby/1.8/puppet/type/exec.rb:125:in `sync'
...
err: /Stage[main]//Exec[test]/returns: change from notrun to 0 failed:
C:/Windows/System32/WindowsPowerShell/v1.0/powers
hell.exe C:/test.ps1 returned 1 instead of one of [0] at
c:/Users/root/AppData/Local/temp/windows.pp:5
</pre>
However, the GPO "Turn on Script Executing" setting taking precedence over the
`execution-policy` you've specified for the `LocalMachine`. From, `powershell
help about_Execution_Policies`
<pre>
The Group Policy setting overrides the execution policies set in Windows
PowerShell in all scopes.
</pre>
So I think you need to modify your `exec` resource as follows:
<pre>
exec { 'test':
command => 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
-executionpolicy remotesigned -file C:/test.ps1',
provider => windows,
logoutput => true,
}
</pre>
Doing so works for me. Can you verify if it works for you?
I'll add a note to the wiki about needing to specify the execution policy.
----------------------------------------
Bug #11482: exec powershell scripts return code 1
https://projects.puppetlabs.com/issues/11482
Author: Marco Peterseil
Status: Needs More Information
Priority: Normal
Assignee: Marco Peterseil
Category: exec
Target version:
Affected Puppet version: 2.7.9
Keywords:
Branch:
i have following ps1 script
# test.ps1
New-Item -Path "c:\yabi" -ItemType Dir
and following config
# windows.pp
exec { 'test':
command => 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
C:/test.ps1',
provider => windows,
}
starting the agent:
puppet agent --server puppetmaster --test
info: Caching catalog for win-1aol6rc6eer
info: Applying configuration version '1324302070'
err: /Stage[main]/Windows/Exec[test]/returns: change from notrun to 0
failed: C:/Windows/System32/WindowsPowerShell/v1.0
/powershell.exe C:/test.ps1 returned 1 instead of one of [0] at
/etc/puppet/manifests/windows/yabi.pp:21
notice: Finished catalog run in 5.23 seconds
if i run the command on powershell, cmd or start-run it is working perfect. so
the script is not the problem.
the execution policy is also set:
PS C:\Users\Administrator> Get-ExecutionPolicy
Unrestricted
a batch file with the "same" content works fine:
# test.bat
mkdir C:\yabi
starting the agent:
PS C:\Users\Administrator> puppet agent --server puppetmaster --test
info: Caching catalog for win-1aol6rc6eer
info: Applying configuration version '1324302937'
notice: /Stage[main]/Windows/Exec[test]/returns: executed successfully
notice: Finished catalog run in 4.83 seconds
ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-mingw32]
Windows Server 2008R2 SP1
Powershell V2.0
--
You have received this notification because you have either subscribed to it,
or are involved in it.
To change your notification preferences, please click here:
http://projects.puppetlabs.com/my/account
--
You received this message because you are subscribed to the Google Groups
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-bugs?hl=en.