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
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?
if len(delimiter) > 1:
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/>
try quoting the delimiter
delimiter=':'
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.
=> template error while templating string: expected token ‘,’, got ‘:’
Above is the error when u do ‘:’
=> template error while templating string: expected token ‘,’, got ‘:’
Above is the error when u do ‘:’
Long story short - I got it fixed. Here is the approach I used. This may not be clean but my work is done.
delimiter=‘“:”’
That's single quotes wrapping double quotes from what I can tell. Would love to understand why that works at some point but great.
Reason why this works is as follows
'—> escaping first level
"—> escaping template parser
Once again appreciate the help.