Variable concatenation

18 views
Skip to first unread message

b...@tanners.org

unread,
Nov 23, 2017, 1:44:29 AM11/23/17
to Ansible Project
Is there a way to concatenate variables?

base:
  - a
  - b
  - c

extend:
  - x
  - y
  - z

Something like this?

together: 
  - "{{ base }""
  - extend

The above gives me

    "msg": "together [[u'a', u'b', u'c'], u'x', u'y', u'z']"



Kai Stian Olstad

unread,
Nov 23, 2017, 9:33:54 AM11/23/17
to ansible...@googlegroups.com
On Thursday, 23 November 2017 07.44.29 CET b...@tanners.org wrote:
> Is there a way to concatenate variables?

Since you variable contains a list you can use the union filter
https://docs.ansible.com/ansible/latest/playbooks_filters.html

But this will remove duplicates or just use +.


> base:
> - a
> - b
> - c
>
> extend:
> - x
> - y
> - z
>
> Something like this?
>
> together:
> - "{{ base }""
> - extend
>
> The above gives me
>
> "msg": "together [[u'a', u'b', u'c'], u'x', u'y', u'z']"

{{ base | union(extend) }}

{{ base + extend }}


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages