# Changing the delimiter for lookup results

**URL:** <https://forum.ansible.com/t/changing-the-delimiter-for-lookup-results/20160>\
**Category:** Ansible Project\
**Created:** [January 8, 2016, 10:24pm UTC](https://forum.ansible.com/t/changing-the-delimiter-for-lookup-results/20160 "2016-01-08T22:24:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesse\_Schluter](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@Jesse\_Schluter](https://forum.ansible.com/u/Jesse_Schluter)\
**Post date:** [January 8, 2016, 10:24pm UTC](https://forum.ansible.com/t/changing-the-delimiter-for-lookup-results/20160/1 "2016-01-08T22:24:12Z")

</div>

Hey everyone,

as I understand, normally a lookup returning a list, will be joined to a string using “,” as a delimiter. Is it possible to change this behavior?

I only found the solution by patching the code. The background of the question is, that I would like to do something like this:

vars:  
ssh\_keys:

- key1
- key2
- key3  
tasks:
- name: set authorized keys exclusive  
authorized\_key: user=root exclusive=yes key=“{{ lookup(‘items’, ssh\_keys, delimiter=‘\n’) }}”

Unfortunately authorized\_key using the exclusive flag is not loop aware. I do already have a patch for 1.9 enabling the delimiter keyword, but I wanted to ask whether there is a “native” solution before bothering the developers with a pull request.

Best regards,  
Jesse

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 8, 2016, 11:07pm UTC](https://forum.ansible.com/t/changing-the-delimiter-for-lookup-results/20160/2 "2016-01-08T23:07:13Z")

</div>

I would instead of looping, just use the |join filter.

---

<div class="post-metadata">

**Author:** ![Jesse\_Schluter](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@Jesse\_Schluter](https://forum.ansible.com/u/Jesse_Schluter)\
**Post date:** [January 9, 2016, 7:39am UTC](https://forum.ansible.com/t/changing-the-delimiter-for-lookup-results/20160/3 "2016-01-09T07:39:13Z")

</div>

If I understand you correctly this would work like this, yes?

vars:  
ssh\_keys\_string: “{{ lookup(‘items’, ssh\_keys, wantlist=True) | join(‘\n’) }}”

I know my example does not make much sense, but I do not actually have the ssh\_key variable as a list of all ssh-keys, but create it via lookup. I just used the items lookup to simplify the example.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 9, 2016, 2:18pm UTC](https://forum.ansible.com/t/changing-the-delimiter-for-lookup-results/20160/4 "2016-01-09T14:18:32Z")

</div>

What I am saying is to literally do:

key=“{{ ssh\_keys|join(‘\n’) }}”

There is no need to use any lookup plugin.

Just join the list with a \n
