ansible.windows.quote (2.3.0) — filter

Quotes argument(s) for various Windows shells

Authors: Jordan Borean (@jborean93)

Install collection

Install with ansible-galaxy collection install ansible.windows:==2.3.0


Add to requirements.yml

  collections:
    - name: ansible.windows
      version: 2.3.0

Description

Quotes argument(s) for the various Windows command line shells.

Defaults to escaping arguments based on the Win32 C argv parsing rules that M(ansible.windows.win_command) uses.

Using I(shell='cmd') or I(shell='powershell') can be set to escape arguments for those respective shells.

Each value is escaped in a way to ensure the process gets the literal argument passed in and meta chars escaped.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Escape an argument for win_command
  ansible.windows.win_command:
    cmd: my.exe {{ argument1 | ansible.windows.quote }}
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Escape an argument for PowerShell
  ansible.windows.win_shell: |
    $var = {{ argument1 | ansible.windows.quote(shell='powershell') }}
    Write-Host $var

Inputs

    
shell:
    choices:
    - None
    - cmd
    - powershell
    default: None
    description:
    - The shell to quote the arguments for.
    - By default no shell is used and the arguments are quoted with the Win32 C quoting
      rules.
    type: string

_input:
    description:
    - The string, list, or dict of values to quote.
    - A string or list of strings will be quoted.
    - When using a dict as the input, the final form will be in C(KEY="value") to match
      the MSI parameter format.
    required: true
    type: raw

Outputs

_value:
  description:
  - The quoted input value(s) as a single space delimited string.
  type: string

See also