# csvfile lookup plugin with a space-delimited file

**URL:** <https://forum.ansible.com/t/csvfile-lookup-plugin-with-a-space-delimited-file/20898>\
**Category:** Ansible Project\
**Created:** [March 17, 2016, 1:29am UTC](https://forum.ansible.com/t/csvfile-lookup-plugin-with-a-space-delimited-file/20898 "2016-03-17T01:29:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_Buddhdev](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@Anand\_Buddhdev](https://forum.ansible.com/u/Anand_Buddhdev)\
**Post date:** [March 17, 2016, 1:29am UTC](https://forum.ansible.com/t/csvfile-lookup-plugin-with-a-space-delimited-file/20898/1 "2016-03-17T01:29:39Z")

</div>

Hello Ansible folk,

I have a text file of the form:

10.60.43.23 worker22.domain

I was to use the “csvfile” lookup plugin to look up name host name, given an IP address. So I’m trying this:

- name: hostname lookup  
debug:  
msg: hostname is {{ lookup(“csvfile”,ansible\_default\_ipv4[“address”]+" file=hostnames.hdp1 delimiter=’ '") }}

However, running this snippet gives me the error:

TASK [hostname lookup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [worker22.domain]: FAILED! =\> {“failed”: true, “msg”: “need more than 1 value to unpack”}

I can’t understand what Ansible is actually failing on. I’ve tried to run with -vvvv, but it seems this error occurs before the debug module is even transferred to the remote host for execution. If anyone knows what this error means, and how I can avoid it, I would greatly appreciate the help.

Regards,

Anand

---

<div class="post-metadata">

**Author:** ![Uditha\_Desilva](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@Uditha\_Desilva](https://forum.ansible.com/u/Uditha_Desilva)\
**Post date:** [March 18, 2016, 1:23pm UTC](https://forum.ansible.com/t/csvfile-lookup-plugin-with-a-space-delimited-file/20898/2 "2016-03-18T13:23:08Z")

</div>

Check that your file is sorted, and doesn’t have any blank lines. Similar issues led me to abandon that and use an awk invocation via “with\_lines:” to pull the data out that I needed.

---

<div class="post-metadata">

**Author:** ![Uditha\_Desilva](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@Uditha\_Desilva](https://forum.ansible.com/u/Uditha_Desilva)\
**Post date:** [March 18, 2016, 10:01pm UTC](https://forum.ansible.com/t/csvfile-lookup-plugin-with-a-space-delimited-file/20898/3 "2016-03-18T22:01:46Z")

</div>

Here’s what I suggest for your case:

- name: hostname lookup  
debug:  
msg: “hostname is {{ item }}”  
with\_lines: “awk ‘$1=="{{ansible\_default\_ipv4[‘address’]}}"{print $2;exit}’ hostnames.hdp1”  
changed\_when: false
