Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script module can't run powershell scripts when environment block exists #22441

Closed
ar7z1 opened this issue Mar 9, 2017 · 0 comments · Fixed by #22927
Closed

Script module can't run powershell scripts when environment block exists #22441

ar7z1 opened this issue Mar 9, 2017 · 0 comments · Fixed by #22927
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. module This issue/PR relates to a module. windows Windows community

Comments

@ar7z1
Copy link
Contributor

ar7z1 commented Mar 9, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

script

ANSIBLE VERSION
ansible 2.3.0 (devel 0f82674c0e) last updated 2017/03/09 13:49:25 (GMT +300)
  config file = /home/art/.ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
CONFIGURATION
OS / ENVIRONMENT

Managing Windows OS.

SUMMARY

Script module can't run powershell scripts when environment block exists.

STEPS TO REPRODUCE

I'm trying to pass environment variable to the script:

- name: Run test script
  script: files/test.ps1
  environment:
    testVar: "Test"

I originally needed to run such task to install Chocolatey behind a proxy server. To execute step 3 of the instruction I need to run:

- name: Install chocolatey
  script: files/install.ps1
  environment:
    chocolateyProxyLocation: "http://proxy:8080"
EXPECTED RESULTS

I expect the operation to succeed:

changed: [hostname] => {
    "changed": true,
    "rc": 0,
    "stderr": "",
    "stdout": "Test\r\n",
    "stdout_lines": [
        "Test"
    ]
}
ACTUAL RESULTS

But I got the error:

fatal: [hostname]: FAILED! => {
    "changed": true,
    "failed": true,
    "rc": 1,
    "stderr": "& : The term '=Test' is not recognized as the name of a cmdlet, function, \r\nscript file, or operable program. Check the spelling of the name, or if a path \r\nwas included, verify that the path is correct and try again.\r\nAt line:1 char:3\r\n+ & $env:testVar='Test' \r\n'C:\\Users\\ansible\\AppData\\Local\\Temp\\ansible-tmp-148905666 ...\r\n+   ~~~~~~~~~~~~~~~~~~~\r\n    + CategoryInfo          : ObjectNotFound: (=Test:String) [], CommandNotFou \r\n   ndException\r\n    + FullyQualifiedErrorId : CommandNotFoundException\r\n \r\n\r\n",
    "stdout": "",
    "stdout_lines": []
}
@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. labels Mar 9, 2017
@rcarrillocruz rcarrillocruz removed the needs_triage Needs a first human triage before being processed. label Mar 10, 2017
ar7z1 added a commit to ar7z1/ansible that referenced this issue Mar 18, 2017
nitzmahone added a commit to nitzmahone/ansible that referenced this issue Mar 24, 2017
* fixes ansible#22441
* fixes ansible#22655
* moves all env handling into the exec wrapper; this should work for everything but raw, which is consistent with non-Windows.
nitzmahone added a commit that referenced this issue Mar 24, 2017
* fixes #22441
* fixes #22655
* moves all env handling into the exec wrapper; this should work for everything but raw, which is consistent with non-Windows.

(cherry picked from commit cc68212)
nitzmahone added a commit that referenced this issue Mar 24, 2017
* fixes #22441
* fixes #22655
* moves all env handling into the exec wrapper; this should work for everything but raw, which is consistent with non-Windows.
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@dagwieers dagwieers added the windows Windows community label Feb 8, 2019
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. module This issue/PR relates to a module. windows Windows community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants