Score:2

How to join values of 2 lists in ansible

cn flag

I have below mentioned 2 lists

foo: '1', '2', '3',

bar: 'a', 'b', 'c',

I want to combine the values of 2 list and get the below output in ansible. i tried using map attribute but getting error while using 2 map attributes together.

result: '1_a' '2_b' '3_c'

br flag
Neither the variables *foo* and *bar*, not the expected result ``result: '1_a' '2_b' '3_c'`` are valid [YAML](http://www.yamllint.com/). Edit the question and make it [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example).
Score:1
br flag

For example, given the lists

  foo: ['1', '2', '3']
  bar: ['a', 'b', 'c']

the expression below

  result: "{{ foo|zip(bar)|map('join', '_')|list }}"

gives

  result: [1_a, 2_b, 3_c]
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.