Proper way to concatenate variable strings in Ansible


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

The problem is:

  • Usage of {{ var1 }}...{{ varN }} brings too long strings and very ugly code.
  • Usage of {{ newvar.stdout }} a bit better but confusing.
  • Usage of set_fact module caches fact between runs. It isn’t appropriate for me.

Is there any other solution?


Good question. But I think there is no good answer which fits your criteria. The best I can think of is to use an extra vars file.

A task like this:

And in concat.yml you have your definition:

Leave a Reply