Skip to content

win_command incorrectly parses args containing spaces #23019

@johnboy2

Description

@johnboy2
ISSUE TYPE
  • Bug Report
COMPONENT NAME

win_command

ANSIBLE VERSION
ansible 2.2.1.0
CONFIGURATION

n/a

OS / ENVIRONMENT

Windows Server 2012 r2 (target host); Ubuntu 16.04 (management system)

SUMMARY

Double-quoted commands containing spaces are incorrectly parsed by "win_command.ps1", causing arguments to be split incorrectly before execution.

STEPS TO REPRODUCE

Example playbook demonstrating this issue:

- hosts: windows
  gather_facts: false
  tasks:
  - win_command: C:\windows\system32\netsh.exe advfirewall firewall show rule name="File and Printer Sharing (SMB-In)"
    register: win_command_output
    failed_when: false
  - debug: var=win_command_output
  vars:
    ansible_user: Administrator
    ansible_password: FIXME
    ansible_port: 5986
    ansible_connection: winrm
    ansible_winrm_server_cert_validation: ignore
EXPECTED RESULTS
  • win_command_output.rc == 0
  • win_command_output.stdout encodes a table of firewall rule information.
ACTUAL RESULTS
  • win_command_output.rc == 1
  • win_command_output.stdout contains an usage/invocation error
NOTES
  • The issue can be traced to incorrect handling of the command string after it is passed to "win_command.ps1".
  • The relevant processing logic of the current implementation can be summarized as follows:
    1. It parses the command from a single string into a list of strings (and appears to do so correctly).
    2. It uses that list to infer the "command" (ie list's first entry), as distinct from the "arguments" (ie everything in the list after the first entry, if any).
    3. It then re-assembles a single string containing just the arguments by simply joining the individual arguments strings together with a space between each entry. This is incorrect behavior whenever there are any arguments containing a space, tab, or double-quote.
  • For MS' escaping rules, see https://msdn.microsoft.com/en-us/library/17w5ykft.aspx.
  • Workarounds may be developed using either "win_raw" or "win_shell".

Metadata

Metadata

Assignees

Labels

affects_2.2This issue/PR affects Ansible v2.2affects_2.3This issue/PR affects Ansible v2.3affects_2.4This issue/PR affects Ansible v2.4bugThis issue/PR relates to a bug.moduleThis issue/PR relates to a module.support:coreThis issue/PR relates to code supported by the Ansible Engineering Team.windowsWindows community

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions