Uploaded image for project: 'Puppet Task Runner'
  1. Puppet Task Runner
  2. BOLT-536

Default input method of PowerShell files does not appear to be powershell, but STDIN

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: BOLT 0.20.2
    • Fix Version/s: BOLT 0.20.6
    • Component/s: Windows
    • Environment:

      Bolt Host - Windows 10 - 1803, Ruby 2.3.3, Bolt 0.22.2
      Windows Target VM - Windows 2012r2

    • Template:
    • Acceptance Criteria:
      Hide
      • Either the docs and specs need to be updated that the powershell input is not default

      OR

      • Files with a .ps1 extension and have metadata, should default to the powershell input method
      Show
      Either the docs and specs need to be updated that the powershell input is not default OR Files with a .ps1 extension and have metadata, should default to the powershell input method
    • Sprint:
      Bolt Kanban
    • Method Found:
      Needs Assessment
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Fixed an issue where Bolt did not default to the 'powershell' input type for powershell scripts run over WinRM.
    • QA Risk Assessment:
      Needs Assessment

      Description

      I was trying to create a bolt task for the WSUS_Client module using a simple powershell script, however the bolt parameters were not passing through. According to the specs (https://github.com/puppetlabs/puppet-specifications/tree/master/tasks#powershell) and docs (https://puppet.com/docs/bolt/0.x/writing_tasks.html#defining-parameters-in-windows) I just need to add name parameters but this is not true. I had to manually add "input_method": "powershell" to the task metadata in order to get parameters passed.

      Repro:

      installed_updates.ps1

      [CmdletBinding()]
      Param(
        [Parameter(Mandatory = $False)]
        [String]$description = ''
      )
       
      Write-Output "############### DESC = ${Description}"
      

      installed_updates.json

      {
        "description": "Returns a list of installed Windows Updates.",
        "parameters": {
          "description": {
            "description": "Return only updates which have this description, for example 'Update' or 'Security Update'",
            "type": "String"
          }
        },
      }
      

      * Run bolt (substitute directories etc. as required)
      be bolt --nodes 192.168.100.116 --transport winrm --user Administrator --Password ***** --no-ssl --modulepath spec/fixtures/modules task run wsus_client::installed_updates description=Update --debug

      Expected Output:

      ...
      Running task wsus_client::installed_updates with '{"description"=>"Update"}' via powershell on ["192.168.100.116"]
      ...
      <Lots of text>
      ...
      try { & "C:\Users\Administrator\AppData\Local\Temp\k1vavurm.fs0\installed_updates.ps1" @taskArgs } catch { Write-Error $_.Exception; exit 1 }
       
      stdout: ############### DESC = Update
       
      stderr:
      Command returned successfully
      Executing command: Remove-Item -Force "C:\Users\Administrator\AppData\Local\Temp\k1vavurm.fs0\installed_updates.ps1"
      Remove-Item -Force "C:\Users\Administrator\AppData\Local\Temp\k1vavurm.fs0"
       
      Command returned successfully
      Closed session
      {"node":"192.168.100.116","status":"success","result":{"_output":"############### DESC = Update\r\n"}}
      Finished on 192.168.100.116:
        ############### DESC = Update
        {
        }
      Finished: task wsus_client::installed_updates with 0 failures in 8.71 sec
      Successful on 1 node: 192.168.100.116
      Ran on 1 node in 8.88 seconds
      

      Note the 'DESC = Update' section

      Actual Output

      ...
      Running task wsus_client::installed_updates with '{"description"=>"Update"}' via both on ["192.168.100.116"]
      ...
      <Lots of text>
      ...
      $invokeArgs = @{
        Path = "powershell.exe"
        Arguments = $quoted_array -Join ' '
        Timeout = 600
        StdinInput = @'
      {"description":"Update"}
      '@
      }
       
      # winrm gem checks $? prior to using $LASTEXITCODE
      # making it necessary to exit with the desired code to propagate status properly
      exit $(Invoke-Interpreter @invokeArgs)
       
      stdout: ############### DESC =
       
      stderr:
      Command returned successfully
      Executing command: Remove-Item -Force "C:\Users\Administrator\AppData\Local\Temp\1prfwcm2.f54\installed_updates.ps1"
      Remove-Item -Force "C:\Users\Administrator\AppData\Local\Temp\1prfwcm2.f54"
       
      Command returned successfully
      Closed session
      {"node":"192.168.100.116","status":"success","result":{"_output":"############### DESC = \r\n"}}
      Finished on 192.168.100.116:
        ############### DESC =
        {
        }
      Finished: task wsus_client::installed_updates with 0 failures in 12.52 sec
      Successful on 1 node: 192.168.100.116
      Ran on 1 node in 12.70 seconds
      

      Note that 'DESC =' is empty and that at the top is a reference to passing through StdinInput = @' ...

      Workaround

      Explicitly adding the input method makes the task parameter passing work

      installed_updates.json

      {
        "description": "Returns a list of installed Windows Updates.",
        "parameters": {
          "description": {
            "description": "Return only updates which have this description, for example 'Update' or 'Security Update'",
            "type": "String"
          }
        },
        "input_method": "powershell"
      }
      

        Attachments

          Issue Links

            Activity

              jsd-sla-details-panel

                People

                • Assignee:
                  cas.donoghue Cas Donoghue
                  Reporter:
                  glenn.sarti Glenn Sarti
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: