ansible.windows.quote 过滤器 – 为各种 Windows shell 引用参数

注意

此过滤器插件是 ansible.windows 集合(版本 2.5.0)的一部分。

如果您使用的是 ansible 包,您可能已经安装了这个集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install ansible.windows

要在剧本中使用它,请指定: ansible.windows.quote

概要

  • 为各种 Windows 命令行 shell 引用参数。

  • 默认情况下,基于 ansible.windows.win_command 使用的 Win32 C argv 解析规则转义参数。

  • 可以使用 shell='cmd'shell='powershell' 来设置为各自的 shell 转义参数。

  • 每个值都以确保进程获得传入的文字参数并且元字符被转义的方式进行转义。

输入

这描述了过滤器的输入,即 | ansible.windows.quote 之前的值。

参数

注释

输入

any / required

要引用的字符串、列表或字典的值。

字符串或字符串列表将被引用。

当使用字典作为输入时,最终形式将为 KEY="value" 以匹配 MSI 参数格式。

关键字参数

这描述了过滤器的关键字参数。这些是以下示例中的值 key1=value1key2=value2 等: input | ansible.windows.quote(key1=value1, key2=value2, ...)

参数

注释

shell

string

要为其引用参数的 shell。

默认情况下,不使用任何 shell,并且参数使用 Win32 C 引用规则进行引用。

选择

  • "None" ← (默认)

  • "cmd"

  • "powershell"

另请参阅

另请参阅

ansible.windows.win_command

在远程 Windows 节点上执行命令。

ansible.windows.win_shell

在目标主机上执行 shell 命令。

示例

- name: Escape an argument for win_command
  ansible.windows.win_command:
    cmd: my.exe {{ argument1 | ansible.windows.quote }}

- name: Escape an argument for PowerShell
  ansible.windows.win_shell: |
    $var = {{ argument1 | ansible.windows.quote(shell='powershell') }}
    Write-Host $var

返回值

描述

返回值

string

引用的输入值作为单个空格分隔的字符串。

Returned: success

作者

  • Jordan Borean (@jborean93)

提示

每个条目类型的配置条目都有一个从低到高的优先级顺序。例如,列表中较低的变量将覆盖较高的变量。