2017-07-26 58 views
0

假设串连我有ansible数组:遍历变量,并用绳子

vars: 
    loopme: ['somesing', 'someothersing'] 
    concatenateme: 'constant' 

我如何遍历目录和CONCAT值从列表与变量concatenateme?

因此,我得到somesingconstantsomeothersingconstant并将结果放入任务中的字段?也许与忍者?

回答

2

您可以使用mapregex_replace过滤器应用到列表中的每个元素和替换“字符串的结束”($)与不变:


- hosts: localhost 
    gather_facts: no 
    vars: 
    loopme: ['somesing', 'someothersing'] 
    concatenateme: 'constant' 
    tasks: 
    - debug: 
     msg: "{{ loopme | map('regex_replace','$',concatenateme) | list }}" 
+0

这将是一个数组? – 4c74356b41

+1

是的,它会是一个列表:'[“somesingconstant”,“someothersingconstant”]' –