Ansible Tower传递参数至PowerShell脚本时路径被截断问题求助
问题解决:Ansible传递带空格的路径参数给PowerShell时被截断
问题原因
参数中包含空格时,直接拼接在script模块的脚本路径后,Shell会将空格作为参数分隔符,把/Microsoft SQL Server/files/blah拆分成多个独立参数,导致PowerShell脚本仅接收到第一个部分/Microsoft。
解决方案
方案1:通过args.arguments传递参数
将参数与脚本路径分离,使用args.arguments字段传递,Ansible会自动处理带空格的参数,避免被Shell拆分:
- name: Deploy Report hosts: ****** tasks: - name: Run Powershell Script script: "../deploy.ps1" args: executable: powershell arguments: "-input1 '{{ input1 }}'"
方案2:用quote过滤器包裹变量
通过Ansible的quote过滤器自动为带空格的变量添加合适引号,确保参数作为一个整体传递:
- name: Deploy Report hosts: ****** tasks: - name: Run Powershell Script script: "../deploy.ps1 -input1 {{ input1 | quote }}" args: executable: powershell
内容的提问来源于stack exchange,提问作者Daniel Zamloot
相关产品推荐
相关产品推荐

