Search code examples
powershellsalt-project

saltstack: run powershell script in a state


I'm trying to download uru from bitbucket and try to install using vagrant with default login credentials. I'm able to download the archive. When ever I try to run the script see this error - Invalidly-formated env parameter. See documentation. I'm able to run the script without any errors. I'm running this locally using vagrant in masterless mode. Any help is really appreciated.

download_uru:
  file.managed:
    - name: c:\uru-0.8.3-windows-x86.7z
    - source: https://bitbucket.org/jonforums/uru/downloads/uru-0.8.3-windows-x86.7z
    - source_hash: sha256=f2a7b4ed8ef6b02613b134da19a31293c7423e8fbbd8e49ec5c1c86c5f3a0815

install_uru:
  cmd.run:
    - source: salt://ruby/files/install_uru.ps1
    - shell: powershell
    - env: "-ExecutionPolicy bypass"
    - runas: "vagrant"
    - password: "vagrant"
    - require:
      - file: download_uru

$cat install_uru.ps1

set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"

sz x -oC: C:\uru-0.8.3-windows-x86.7z -r ;

c:\salt\salt-call.bat --version

salt-call 2016.11.3 (Carbon)


Solution

  • Your problem is due to the wrong format of the -env parameter. As described in the official documentation it must be a list and you are setting a string.

    Fix the install_uru state like the code below and it will run correctly.

    install_uru:
      cmd.run:
        - source: salt://ruby/install_uru.ps1
        - shell: powershell
        - env: 
          - ExecutionPolicy: "bypass"
        - runas: "vagrant"
        - password: "vagrant"
        - require:
          - file: download_uru