Git Product home page Git Product logo

Comments (3)

donoghuc avatar donoghuc commented on June 20, 2024

You should be able to configure this in the interpreters config for .ps1 files https://www.puppet.com/docs/bolt/latest/bolt_transports_reference.html#interpreters

from bolt.

coolhome avatar coolhome commented on June 20, 2024

@donoghuc I had no idea about this. Thank you!

Is it expected that if a task input_method is powershell that you cannot define interpreters? If I set this to stdin it actually runs in pwsh.exe instead of powershell.exe.

Reproduction:

bolt-project.yaml:

---
name: bolt_pwsh_task
modules: []

inventory:

config:
  local:
    interpreters:
      ".ps1": "C:\\Program Files\\PowerShell\\7\\pwsh.exe"

working but no named parameters tasks/init.json:

{
    "input_method": "stdin",
    "parameters": {
        "name": {
            "description": "Name of user to run command",
            "type": "String"
        }
    }
}

always powershell.exe but working named params tasks/init.json:

{
    "input_method": "powershell",
    "parameters": {
        "name": {
            "description": "Name of user to run command",
            "type": "String"
        }
    }
}

tasks/init.ps1:

#!/usr/bin/env pwsh
[CmdletBinding()]
param (
    [Parameter()]
    [string]
    $name
)

Write-Host "PSEdition = $($PSEdition)"
$PSVersionTable
Write-Host "Name = $($Name)"

Appears to be intentional to not allow overriding

command = if powershell_file?(task_path) && stdin.nil?
run_ps_task(task_path, arguments, input_method)
else
if (interpreter = select_interpreter(task_path, target.options['interpreters']))
# interpreter can be a String or Array here. Cast it to an array.
interpreter_array = Array(interpreter)
# Make path the first part of the array - this should be the binary
path = interpreter_array.shift
# Anything else in interpreters should get prepended to
# the command. If interpreters was a string this will
# just be [task_path]
args = interpreter_array + [task_path]
else
path, args = *process_from_extension(task_path)
end
execute_process(path, args, stdin)
end

def run_ps_task(task_path, arguments, input_method)
# NOTE: cannot redirect STDIN to a .ps1 script inside of PowerShell
# must create new powershell.exe process like other interpreters
# fortunately, using PS with stdin input_method should never happen
if input_method == 'powershell'
Snippets.ps_task(task_path, arguments)
else
Snippets.try_catch(task_path)
end
end

from bolt.

coolhome avatar coolhome commented on June 20, 2024

I'm closing because I found much more success using Plans + Script Task. I think it's a bit weird powershell.exe is forced on windows, for non-windows management pwsh is great.

from bolt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.