Proper way to concatenate variable strings

后端 未结 3 927
夕颜
夕颜 2021-02-01 01:36

I need to create new variable from contents of other variables. Currently I\'m using something like this:

- command: echo \"{{ var1 }}-{{ var2 }}-{{ var3 }}\"
           


        
3条回答
  •  执念已碎
    2021-02-01 02:05

    As simple as joining lists in python itself.

    ansible -m debug -a msg="{{ '-'.join(('list', 'joined', 'together')) }}" localhost
    

    localhost | SUCCESS => {
      "msg": "list-joined-together" }
    

    Works the same way using variables:

    ansible -m debug -a msg="{{ '-'.join((var1, var2, var3)) }}" localhost
    

提交回复
热议问题