# csvlookups referencing variables

**URL:** <https://forum.ansible.com/t/csvlookups-referencing-variables/19327>\
**Category:** Ansible Project\
**Created:** [September 22, 2015, 2:38pm UTC](https://forum.ansible.com/t/csvlookups-referencing-variables/19327 "2015-09-22T14:38:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Wolff](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@Nick\_Wolff](https://forum.ansible.com/u/Nick_Wolff)\
**Post date:** [September 22, 2015, 2:38pm UTC](https://forum.ansible.com/t/csvlookups-referencing-variables/19327/1 "2015-09-22T14:38:22Z")

</div>

Hello all,

I’m trying to do a csvlookup that references a variable so I can dynamically choose which line of the file. I tried the first two thinks to do the lookup with name only the third directly referencing the name works

- hosts: “{{ target }}”  
vars:  
name : “REALUSER”  
uid : “{{ lookup(‘csvfile’, ''name delimiter=: file=/etc/passwd col=2 ') }}”  
gid : ‘{{ lookup(“csvfile”, name + “file=/etc/passwd col=3 delimiter=:”) }}’  
comment : ‘{{ lookup(“csvfile”, “REALUSER file=/etc/passwd delimiter=: col=4”) }}’  
tasks:
- debug: msg=“The uid is {{ uid }} and the name is {{name}} and the gid is {{ gid }}”

---

<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:** [September 22, 2015, 2:56pm UTC](https://forum.ansible.com/t/csvlookups-referencing-variables/19327/2 "2015-09-22T14:56:24Z")

</div>

the 2nd one is right, but you need a space:

'{{ lookup("csvfile", name + " file=/etc/passwd col=3 delimiter=:") }}'

---

<div class="post-metadata">

**Author:** ![Nick\_Wolff](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@Nick\_Wolff](https://forum.ansible.com/u/Nick_Wolff)\
**Post date:** [September 22, 2015, 4:25pm UTC](https://forum.ansible.com/t/csvlookups-referencing-variables/19327/3 "2015-09-22T16:25:20Z")

</div>

If I do that I get back

[WARNING]: non fatal error while trying to template play variables: Failed to  
template {{ lookup(“csvfile”, name + " file=/etc/passwd col=3 delimiter=:")  
}}: csvfile: “delimiter” must be an 1-character string

---

<div class="post-metadata">

**Author:** ![Nick\_Wolff](https://avatars.discourse-cdn.com/v4/letter/n/50afbb/32.png) [@Nick\_Wolff](https://forum.ansible.com/u/Nick_Wolff)\
**Post date:** [October 14, 2015, 4:53pm UTC](https://forum.ansible.com/t/csvlookups-referencing-variables/19327/4 "2015-10-14T16:53:19Z")

</div>

Still can’t figure this out if anyone has any ideas.

Thanks,

Nick Wolff
