8000 powershell edition is switched to powershell.exe with become even with pwsh.exe · Issue #84604 · ansible/ansible · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
powershell edition is switched to powershell.exe with become even with pwsh.exe #84604
Open
@yangskyboxlabs

Description

@yangskyboxlabs

Summary

When using PowerShell.7 as the remote configuration for Windows, become: true will always use powershell.exe, which breaks scripts that only work with PowerShell-7.

Issue Type

Bug Report

Component Name

runas

Ansible Version

ansible [core 2.17.5]
  config file = /home/yzhao/ansible/ansible.cfg
  configured module search path = ['/home/yzhao/ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/yzhao/ansible/.venv/lib/python3.12/site-packages/ansible
  ansible collection location = /home/yzhao/ansible/collections:/usr/share/ansible/collections
  executable location = /home/yzhao/ansible/.venv/bin/ansible
  python version = 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] (/home/yzhao/ansible/.venv/bin/python3)
  jinja version = 3.1.4
  libyaml = True

Configuration

ANSIBLE_HOME(/home/yzhao/ansible/ansible.cfg) = /home/yzhao/ansible
CONFIG_FILE() = /home/yzhao/ansible/ansible.cfg
DEFAULT_HOST_LIST(/home/yzhao/ansible/ansible.cfg) = ['/home/yzhao/ansible/hosts', '/home/yzhao/ansible/hosts.local.yml']

OS / Environment

Linux SB-PC-YZHAO4 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Distributor ID: Ubuntu
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Codename: noble

Steps to Reproduce

Using ansible_psrp_configuration_name=PowerShell.7 to explicitly request pwsh.exe for the whole session:

# pwsh_test.yml

- name: Powershell tests
  hosts: SB-PC-IPBUILD3.skyboxlabs.com
  gather_facts: false
  vars:
    ansible_psrp_configuration_name: PowerShell.7
  tasks:
    - name: Print version
      ansible.windows.win_powershell:
        script: echo $PSVersionTable.PSVersion.Major
      check_mode: false

Expected Results

(some formatting changed for brevity)

Expecting output to be 7.

$ ansible-playbook pwsh_test.yml --diff -v --check -b
PLAY [Powershell tests] *****************************************************************************************************************************************************

TASK [Print version] *****************************************************************************************************************************************************
changed: [SB-PC-IPBUILD3.skyboxlabs.com] => {"changed": true, "debug": [], "error": [], "host_err": "", "host_out": "", "information": [], "output": [7], "result": {}, "verbose": [], "warning": []}

PLAY RECAP ****************************************************************************************************************************************
SB-PC-IPBUILD3.skyboxlabs.com : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Actual Results

Expecting `output` is `5`.

$ ansible-playbook pwsh_test.yml --diff -vvvv --check -b
ansible-playbook [core 2.17.5]
  config file = /home/yzhao/ansible/ansible.cfg
  configured module search path = ['/home/yzhao/ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/yzhao/ansible/.venv/lib/python3.12/site-packages/ansible
  ansible collection location = /home/yzhao/ansible/collections:/usr/share/ansible/collections
  executable location = /home/yzhao/ansible/.venv/bin/ansible-playbook
  python version = 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] (/home/yzhao/ansible/.venv/bin/python3)
  jinja version = 3.1.4
  libyaml = True
Using /home/yzhao/ansible/ansible.cfg as config file
setting up inventory plugins
Loading collection ansible.builtin from 
host_list declined parsing /home/yzhao/ansible/hosts as it did not pass its verify_file() method
script declined parsing /home/yzhao/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /home/yzhao/ansible/hosts as it did not pass its verify_file() method
Parsed /home/yzhao/ansible/hosts inventory source with yaml plugin
setting up inventory plugins
host_list declined parsing /home/yzhao/ansible/hosts.local.yml as it did not pass its verify_file() method
script declined parsing /home/yzhao/ansible/hosts.local.yml as it did not pass its verify_file() method
Parsed /home/yzhao/ansible/hosts.local.yml inventory source with yaml plugin
Loading collection ansible.windows from /home/yzhao/ansible/.venv/lib/python3.12/site-packages/ansible_collections/ansible/windows
Loading callback plugin default of type stdout, v2.0 from /home/yzhao/ansible/.venv/lib/python3.12/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: pwsh_test.yml *************************************************************************************************************************************************************************************************************************************************
Positional arguments: pwsh_test.yml
verbosity: 4
connection: ssh
become: True
become_method: sudo
tags: ('all',)
check: True
diff: True
inventory: ('/home/yzhao/ansible/hosts', '/home/yzhao/ansible/hosts.local.yml')
forks: 5
1 plays in pwsh_test.yml

PLAY [Powershell tests] *************************************************************************************************************************************************************************************************************************************************

TASK [Print version] ****************************************************************************************************************************************************************************************************************************************************
task path: /home/yzhao/ansible/pwsh_test.yml:7
Using module file /home/yzhao/ansible/.venv/lib/python3.12/site-packages/ansible_collections/ansible/windows/plugins/modules/win_powershell.ps1
Pipelining is enabled.
<SB-PC-IPBUILD3.skyboxlabs.com> ESTABLISH PSRP CONNECTION FOR USER: adm.yzhao@SKYBOXLABS.COM ON PORT 5985 TO SB-PC-IPBUILD3.skyboxlabs.com
PSRP: EXEC (via pipeline wrapper)
changed: [SB-PC-IPBUILD3.skyboxlabs.com] => {
    "changed": true,
    "debug": [],
    "error": [],
    "host_err": "",
    "host_out": "",
    "information": [],
    "invocation": {
        "module_args": {
            "arguments": null,
            "chdir": null,
            "creates": null,
            "depth": 2,
            "error_action": "continue",
            "executable": null,
            "parameters": null,
            "removes": null,
            "script": "echo $PSVersionTable.PSVersion.Major",
            "sensitive_parameters": null
        }
    },
    "output": [
        5
    ],
    "result": {},
    "verbose": [],
    "warning": []
}

PLAY RECAP **************************************************************************************************************************************************************************************************************************************************************
SB-PC-IPBUILD3.skyboxlabs.com : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects_2.17bugThis issue/PR relates to a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0