Question:
I need to create new variable from contents of other variables. Currently I’m using something like this:
1 2 3 |
- command: echo "{{ var1 }}-{{ var2 }}-{{ var3 }}" register: newvar |
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?
Answer:
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:
1 2 |
- include_vars: concat.yml |
And in
concat.yml
you have your definition:
1 2 |
newvar: "{{ var1 }}-{{ var2 }}-{{ var3 }}" |