首页 > 解决方案 > 如何防止使用ansible在字符串中添加额外的双引号?

问题描述

以下注册表值具有用双引号括起来的路径。

win_shell: |
        $((Get-ItemProperty HKLM:Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | `
        where { $_.DisplayName -match '{{product_name}}' }).UninstallString) -split " -"
  register: out

卸载字符串值如下(带双引号)

"C:\Program Files (x86)\InstallShield Installation Information\{584775F9-1696-4387-AEB5-86171F6567CC}\Setup-x64.5.0.1.8009.exe"

当我将结果分配给 set_fact 时,它会在字符串中再添加一个双引号。

- set_fact: uninstall_filePath="{{out.stdout_lines.0}}"
- debug: var=uninstall_filePath

ok: [Myremotehost] => {
    "uninstall_filePath": "\"C:\\Program Files (x86)\\InstallShield Installation Information\\{584775F9-1696-4387-AEB5-86171F6567CC}\\Setup-x64.5.0.1.8009.exe\""
}

由于这个额外的双引号,我无法使用此路径进行卸载。如何从字符串中删除双引号?或者如何防止在字符串中添加一个额外的双引号?

标签: powershellansible

解决方案


我认为您必须同时使用双引号和单引号。像这样的东西:

"'this is a string'"

只是玩这些或替代尝试转义字符

\

推荐阅读