Uploaded image for project: 'Modules'
  1. Modules
  2. MODULES-3137

Improve logoutput of Powershell Module

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Normal
    • Resolution: Fixed
    • None
    • None
    • powershell
    • None
    • Hide

      A user will be able to run a powershell script with the powershell exec provider that has cmdlets or statements that writes to the Debug, Verbose, Progress and Error streams. If using logoutput, anything from Debug, Verbose, Progress and Error should be shown. Lastly, none of this should affect executing any powershell script

      Show
      A user will be able to run a powershell script with the powershell exec provider that has cmdlets or statements that writes to the Debug, Verbose, Progress and Error streams. If using logoutput, anything from Debug, Verbose, Progress and Error should be shown. Lastly, none of this should affect executing any powershell script
    • 2
    • Windows 2016-05-04, Windows 2016-05-18

    Description

      As part of MODULES-2962 it was discovered that the stdout output was different between 1.x and 2.x of the module. This ticket will change the behaviour of 2.x module to look like that of 1.x where appropriate.

      Also the DEBUG output should show the decoded XML from the powershellmanager instead of the base64 encoded text.

      Example issue

      Manifest

      exec
      { 'show ps':   command  => '$PSVersionTable',   provider  => powershell, logoutput => false }
      ->
      exec
      { 'onlyif check exit 0':   command  => '"OnlyifExit0"',   onlyif => 'exit 0',   provider  => powershell, }
      ->
      exec
      { 'onlyif check exit 1':   command  => '"OnlyifExit1"',   onlyif => 'exit 1',   provider  => powershell, }
      ->
      exec
      { 'onlyif check noexit':   command  => '"OnlyifNoExit"',   onlyif => '',   provider  => powershell, }
      ->
       
      exec
      { 'unless check exit 0':   command  => '"unlessExit0"',   unless => 'exit 0',   provider  => powershell, }
      ->
      exec
      { 'unless check exit 1':   command  => '"unlessExit1"',   unless => 'exit 1',   provider  => powershell, }
      ->
      exec
      { 'unless check noexit':   command  => '"unlessNoExit"',   unless => '',   provider  => powershell, }
      ->
       
      exec { 'write-host':
        command  => 'Write-Host "Hello"',
        provider  => powershell,
        logoutput => true
      }
       
      exec { 'write-verbose':
        command  => '$VerbosePreference = "Continue";Write-Verbose "Hello"',
        provider  => powershell,
        logoutput => true
      }
       
      exec { 'write-debug':
        command  => '$debugPreference = "Continue";Write-debug "Hello"',
        provider  => powershell,
        logoutput => true
      }
       
      exec { 'write-warning':
        command  => 'Write-warning "Hello"',
        provider  => powershell,
        logoutput => true
      }
       
      exec { 'write-error':
        command  => 'Write-error "Hello"',
        provider  => powershell,
        logoutput => true
      }
       
      exec { 'write-progress':
        command  => 'for ($i = 1; $i -le 100; $i++ ){write-progress -activity "Search in Progress" -status "$i% Complete:" -percentcomplete $i;}',
        provider  => powershell,
        logoutput => true
      }
       
      exec { 'write-output':
        command  => 'Write-output "Hello"',
        provider  => powershell,
        logoutput => true
      }
       
      exec { 'write-host - never log':
        command  => 'Write-host "Should not see this"',
        provider  => powershell,
        logoutput => false
      }
       
      exec { 'write-host - log on error (no error)':
        command  => 'Write-host "Should not see this"',
        provider  => powershell,
        logoutput => on_failure
      }
       
      exec { 'write-host - log on error (with error)':
        command  => 'Write-host "Should see this"; exit 1',
        provider  => powershell,
        logoutput => on_failure
      }
      

      Old

      C:\Users\Administrator>"c:\Program Files\Puppet Labs\Puppet\bin\puppet.bat" apply c:\temp\test.pp --modulepath c:\temp\modules --verbose
      Notice: Compiled catalog for win-edson23cglf.localdomain in environment production in 0.16 seconds
      Info: Applying configuration version '1457119480'
      Notice: /Stage[main]/Main/Exec[show ps]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[onlyif check exit 0]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[onlyif check noexit]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[unless check exit 1]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-host]/returns: Hello
      Notice: /Stage[main]/Main/Exec[write-host]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-verbose]/returns: Hello
      Notice: /Stage[main]/Main/Exec[write-verbose]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-warning]/returns: WARNING: Hello
      Notice: /Stage[main]/Main/Exec[write-warning]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-error]/returns: Write-error "Hello" : Hello
      Notice: /Stage[main]/Main/Exec[write-error]/returns:     + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
      Notice: /Stage[main]/Main/Exec[write-error]/returns:     + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
      Notice: /Stage[main]/Main/Exec[write-error]/returns:
      Error: Write-error "Hello" returned 1 instead of one of [0]
      Error: /Stage[main]/Main/Exec[write-error]/returns: change from notrun to 0 failed: Write-error "Hello" returned 1 instead of one of [0]
      Notice: /Stage[main]/Main/Exec[write-progress]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-output]/returns: Hello
      Notice: /Stage[main]/Main/Exec[write-output]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[commandexit5]/returns: executed successfully
      Info: Class[Main]: Unscheduling all events on Class[Main]
      Notice: Applied catalog in 17.84 seconds
      

      New PR

      C:\Users\Administrator>"c:\Program Files\Puppet Labs\Puppet\bin\puppet.bat" apply c:\temp\test.pp --modulepath c:\source --verbose
      Info: Loading facts
      Notice: Compiled catalog for win-edson23cglf.localdomain in environment production in 0.22 seconds
      Info: Applying configuration version '1457119515'
      Notice: /Stage[main]/Main/Exec[show ps]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[onlyif check exit 0]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[onlyif check noexit]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[unless check exit 1]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-host]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-verbose]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-warning]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-error]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-progress]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[write-output]/returns: Hello
      Notice: /Stage[main]/Main/Exec[write-output]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[commandexit5]/returns: executed successfully
      Notice: Applied catalog in 10.03 seconds
      

      Attachments

        Issue Links

          Activity

            People

              erick Erick Banks
              glenn.sarti Glenn Sarti
              Erick Banks Erick Banks
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support