简体   繁体   English

Ansible-如何将数组作为参数传递给Powershell脚本

[英]Ansible - How to pass an array as argument to a powershell script

I've an array like this : 我有一个像这样的数组:

tab:
  - 'val1'
  - 'val2'

and I want to execute a remote script like : 我想执行一个远程脚本,如:

- name: launch Script
  script: "scripts/script.ps1 -tab {{ tab }}"

But the json format is not well recognized ( [uval1 uval2] ). 但是无法很好地识别json格式( [uval1 uval2] )。 I have to convert it to a powershell format : 我必须将其转换为powershell格式:

$new_tab =  $tab -replace '"','' -replace ']','' -replace '\[','' -split ","

Is there a better solution? 有更好的解决方案吗?

I suggest you use join() 我建议您使用join()

scripts/script.ps1 -tab {{ tab | join(',') }}

and then it will create a string like this: val1,val2 然后它将创建一个这样的字符串:val1,val2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM