Ask Your Question
0

Getting error while executing powershell script from puppet

asked 2015-10-13 06:23:37 -0500

Pandey Manish gravatar image

Hi,

My task is to install Icinga2.exe from powershell script on Window 7.

Please find my powershell script below:

cat TYPE.ps1

start-process "C:\Temp\Icinga2-v2.3.10.exe" 
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Icinga 2 Setup')
Sleep 1
$wshell.SendKeys('~')
$wshell.AppActivate('Icinga 2 Setup')
Sleep 1
$wshell.SendKeys('~')
$wshell.AppActivate('Icinga 2 Setup')
Sleep 1
$wshell.SendKeys('~')
$wshell.AppActivate('Icinga 2 Setup')
Sleep 1
$wshell.SendKeys('~')
$wshell.AppActivate('Icinga 2 Setup')
Sleep 11
$wshell.SendKeys('R')
$wshell.SendKeys('~')

My powershell script is running fine without any error on powershell IDE. But when i am trying to execute the same script from puppet class it gives me error.

===================================================================== C:\Temp>puppet apply newtt.pp

Notice: /Stage[main]/Main/Exec[runpowershellinstall_icinga]/returns: TYPE.ps1: The term 'TYPE.ps1' is not recognized as the name of a cmdlet,

Notice: /Stage[main]/Main/Exec[runpowershellinstallicinga]/returns: function,script file, or operable program. Check the spelling of the name, or Notice: /Stage[main]/Main/Exec[runpowershellinstallicinga]/returns: if a path was included, verify that the path is correct and try again.

Notice: /Stage[main]/Main/Exec[runpowershellinstall_icinga]/returns: At line:1char:1

Notice: /Stage[main]/Main/Exec[runpowershellinstall_icinga]/returns: + TYPE.ps1

Notice: /Stage[main]/Main/Exec[runpowershellinstall_icinga]/returns: + ~~~~~~~~

Notice: /Stage[main]/Main/Exec[runpowershellinstall_icinga]/returns: + CategoryInfo : ObjectNotFound: (TYPE.ps1:String) [], CommandNot

Notice: /Stage[main]/Main/Exec[runpowershellinstall_icinga]/returns: FoundException

Notice: /Stage[main]/Main/Exec[runpowershellinstall_icinga]/returns: + FullyQualifiedErrorId : CommandNotFoundException

Notice: /Stage[main]/Main/Exec[runpowershellinstall_icinga]/returns:

Error: TYPE.ps1 returned 1 instead of one of [0]

Error: /Stage[main]/Main/Exec[runpowershellinstall_icinga]/returns: change from notrun to 0 failed: TYPE.ps1 returned 1 instead of one of [0]

Notice: Finished catalog run in 1.24 seconds

==========================================================

However the same script when i put it in a single line in puppet exec function is working correct.

    exec {"run_powershell_install_icinga":
            path => $::path,
            command => 'start-process "C:\Temp\Icinga2-v2.3.10.exe"; $wshell = New-Object -ComObject wscript.shell; $wshell.AppActivate("Icinga 2 Setup"); Sleep 1; $wshell.SendKeys("~"); $wshell.AppActivate("Icinga 2 Setup"); Sleep 1; $wshell.SendKeys("~"); $wshell.AppActivate("Icinga 2 Setup"); Sleep 1; $wshell.SendKeys("~"); $wshell.AppActivate("Icinga 2 Setup"); Sleep 1; $wshell.SendKeys("~"); $wshell.AppActivate("Icinga 2 Setup"); Sleep 11; $wshell.SendKeys("~"); $wshell.SendKeys("~");',
            cwd => 'C:\Temp',
            provider => powershell,
            logoutput => true,
            }

PLease suggest, why i am getting error while executing ps script to install ICINGA2.exe

If you need icinga2 installer , please find the below download link https://packages.icinga.org/windows/I...

edit retag flag offensive close merge delete

Comments

what is the content of newtt.pp when you have the error?

alexandre gravatar imagealexandre ( 2015-10-13 20:40:18 -0500 )edit

The content of newtt.pp is: exec { "runpowershellinstall_icinga": path => $::path, command => 'TYPE.ps1', cwd => 'C:\Temp', provider => powershell, } Whereas the TYPE.ps1 is the same powershell script shown above.

Pandey Manish gravatar imagePandey Manish ( 2015-10-13 22:54:12 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-10-14 02:04:19 -0500

joshc gravatar image

When using the execresource, you must specify the absolute path to the command, see https://docs.puppetlabs.com/reference.... Moreso, puppet does not know that .ps1 files should be handled by powershell, or any other registered application in PATHEXT.

That said, I would highly recommend using the powershell module as you were doing, since it handles things like different SYSTEMROOT directories, file system redirection, etc. Also you can use puppet's HEREDOC support to inline powershell code directly in your manifest and avoid complex quoting and escaping when trying to pack powershell into a single line.

Finally, since you're just trying to install a package, why not use the package resource and specify the necessary options to install the package silently?

package { 'Icinga2-v2.3.10':
  ensure          => '2.3.10',
  source          => 'C:\Temp\Icinga2-v2.3.10.exe',
  install_options => '/S'
}

Make sure that the package name and version match the DisplayName and DisplayVersion that the application sets in the registry (as shown in Add Remove Programs).

edit flag offensive delete link more

Comments

Thank you :)

Pandey Manish gravatar imagePandey Manish ( 2015-10-14 05:48:31 -0500 )edit

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

Stats

Asked: 2015-10-13 06:23:37 -0500

Seen: 411 times

Last updated: Oct 14 '15