Reputation: 3113
I have list in ansible as
mylist = ["test1", "test2", "test3"]
This is ansible variable.
Now in my some file on remote host i want something like
lineinfile: dest=~/.config line='myvar = ["test1", "test2", "test3"]'
How can i do that using mylist
Upvotes: 1
Views: 4003
Reputation: 207
If you want to show the list's pythonic representation as a string, you'll need to write the string to represent the list representation (brackets), and join the list's values using a delimiter (' ,'
in the example):
lineinfile: dest=~/.config line="myvar = [ {{' ,'.join(myvar) }} ]"
Upvotes: 3
Reputation: 9313
Ordinary files don't know about types etc., you want an ordinary string.
mylist = '["test1", "test2", "test3"]'
lineinfile: dest=~/.config line="myvar = {{ mylist }}"
Upvotes: 0