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


On Friday, 18 March 2016 20:00:14 UTC, Uditha Desilva wrote:
>
> 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.
>
> On Thursday, 17 March 2016 01:29:40 UTC, Anand Buddhdev wrote:
>>
>> 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
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/39705c7e-a7db-46d8-a4db-fdb7ac5ac767%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to