[BOLT-536] Default input method of PowerShell files does not appear to be powershell, but STDIN Created: 2018/05/23  Updated: 2018/06/07  Resolved: 2018/06/07

Status: Resolved
Project: Puppet Task Runner
Component/s: Windows
Affects Version/s: BOLT 0.20.2
Fix Version/s: BOLT 0.20.6

Type: Bug Priority: Major
Reporter: Glenn Sarti Assignee: Cas Donoghue
Resolution: Fixed Votes: 0
Labels: docs-reviewed, resolved-issue-added
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

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


Issue Links:
Blocks
is blocked by PUP-8898 Change default input_method for Task ... Closed
Template:
Acceptance Criteria:
  • 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"
}



 Comments   
Comment by Kate Lopresti [ 2018/06/07 ]

Cas Donoghue Hi Cas, Any release notes you'd like added for this ticket? 

Comment by Cas Donoghue [ 2018/06/07 ]

Kate Lopresti I dont think so. The bug fix makes all the existing docs accurate. 

Comment by Kate Lopresti [ 2018/06/07 ]

Generated at Sun Jun 16 15:47:19 PDT 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.