# lookup -csvfile - special character delimiter

**URL:** <https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132>\
**Category:** Ansible Project\
**Created:** [April 29, 2015, 8:04pm UTC](https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132 "2015-04-29T20:04:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raj\_Desikavinayagomp](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@Raj\_Desikavinayagomp](https://forum.ansible.com/u/Raj_Desikavinayagomp)\
**Post date:** [April 29, 2015, 8:04pm UTC](https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132/1 "2015-04-29T20:04:20Z")

</div>

Hello,  
How to do a lookup of a csvfile with a special character delimiter.

Example

password=“{{lookup (‘csvfile’ , ‘string1 file=/tmp/temp.csv delimiter=: col=2’) }}”

Following is the error displayed

‘string1 file=/tmp/temp.csv delimiter=: col=2’) }}"

In the above case, “:” is the delimiter.

thanks

dnraj

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [April 29, 2015, 9:45pm UTC](https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132/2 "2015-04-29T21:45:57Z")

</div>

Looks like there are a couple of things getting in your way.

The first is that the YAML parser thinks the : (colon without escaping or quoting) is a misplaced key/value delimiter. If you put that in double quotes it passes thru to the next issue that being the csvfile lookup plugin makes a call to csvfile.reader with the delimiter string still wrapped in quotes. The delimiter param must be a single character causing another error.

I guess there are a few ways to go about addressing this in the core.

One is to have special string like COLON (like TAB) that gets converted to its single character form.

The other is to detect the delimiter string is more than a single character and assume that it's probably quoted.

I like the later solution because it handles any sort of quoted character someone may throw at it. I'm not fond of the idea of introducing a regex for an edge case where there wheren't any before. Perhaps a len and split combo like this would suffice?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if len(delimiter) \> 1:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delimiter = delimiter.split(delimiter[0])[1]

Not exactly a bulletproof solution, but it's a pretty low cost fix to the issue.

Thoughts from the core team?

\<tim/\>

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 29, 2015, 9:46pm UTC](https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132/3 "2015-04-29T21:46:38Z")

</div>

try quoting the delimiter

delimiter=':'

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [April 29, 2015, 9:51pm UTC](https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132/4 "2015-04-29T21:51:37Z")

</div>

The problem is that Raj is already inside of a single quoted string inside of a double quoted string. Doing what you suggest trips up the template parser.

---

<div class="post-metadata">

**Author:** ![Raj\_Desikavinayagomp](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@Raj\_Desikavinayagomp](https://forum.ansible.com/u/Raj_Desikavinayagomp)\
**Post date:** [April 29, 2015, 9:52pm UTC](https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132/5 "2015-04-29T21:52:33Z")

</div>

=\> template error while templating string: expected token ‘,’, got ‘:’  
Above is the error when u do ‘:’

---

<div class="post-metadata">

**Author:** ![Raj\_Desikavinayagomp](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@Raj\_Desikavinayagomp](https://forum.ansible.com/u/Raj_Desikavinayagomp)\
**Post date:** [April 29, 2015, 9:52pm UTC](https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132/6 "2015-04-29T21:52:43Z")

</div>

=\> template error while templating string: expected token ‘,’, got ‘:’  
Above is the error when u do ‘:’

---

<div class="post-metadata">

**Author:** ![Raj\_Desikavinayagomp](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@Raj\_Desikavinayagomp](https://forum.ansible.com/u/Raj_Desikavinayagomp)\
**Post date:** [April 29, 2015, 10:13pm UTC](https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132/7 "2015-04-29T22:13:03Z")

</div>

Long story short - I got it fixed. Here is the approach I used. This may not be clean but my work is done.

delimiter=‘“:”’

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [April 29, 2015, 10:33pm UTC](https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132/8 "2015-04-29T22:33:02Z")

</div>

That's single quotes wrapping double quotes from what I can tell. Would love to understand why that works at some point but great.

---

<div class="post-metadata">

**Author:** ![Raj\_Desikavinayagomp](https://avatars.discourse-cdn.com/v4/letter/r/54ee81/32.png) [@Raj\_Desikavinayagomp](https://forum.ansible.com/u/Raj_Desikavinayagomp)\
**Post date:** [April 29, 2015, 10:34pm UTC](https://forum.ansible.com/t/lookup-csvfile-special-character-delimiter/18132/9 "2015-04-29T22:34:53Z")

</div>

Reason why this works is as follows

'—\> escaping first level  
"—\> escaping template parser

Once again appreciate the help.
