# unable to copy ansible vriable into file

**URL:** <https://forum.ansible.com/t/unable-to-copy-ansible-vriable-into-file/31470>\
**Category:** Ansible Project\
**Created:** [October 15, 2019, 8:19am UTC](https://forum.ansible.com/t/unable-to-copy-ansible-vriable-into-file/31470 "2019-10-15T08:19:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhay\_srivastava](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@abhay\_srivastava](https://forum.ansible.com/u/abhay_srivastava)\
**Post date:** [October 15, 2019, 8:19am UTC](https://forum.ansible.com/t/unable-to-copy-ansible-vriable-into-file/31470/1 "2019-10-15T08:19:29Z")

</div>

Error:

TASK [lineinfile] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [192.168.1.158]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘list object’ has no attribute u’0’\n\nThe error appears to be in ‘/home/cloud/nidhi/ccepbook/nidhi-playbook.yml’: line 31, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - local\_action: lineinfile line="{{ result.results[item].container.Config.Hostname }}" dest=/tmp/abhay.csv\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with\_items:\n - {{ foo }}\n\nShould be written as:\n\n with\_items:\n - "{{ foo }}"\n”}

- local\_action: lineinfile line=“{{ result.results[item].container.Config.Hostname }}” dest=/tmp/abhay.csv  
with\_sequence: start=0 end=“{{ count|int }}”

here count is from 0 to 2

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [October 15, 2019, 9:20am UTC](https://forum.ansible.com/t/unable-to-copy-ansible-vriable-into-file/31470/2 "2019-10-15T09:20:07Z")

</div>

The error is telling you exactly what the problem is. You need to work out what might be causing that problem.

In this case, a list object does not have an attribute called (in Unicode) ‘0’.

Your loop uses values from a sequence, and the first in the sequence is ‘0’. This is used to dereference the variable result.results (as in, result.results[item]…).

I’m guessing that result.results is an empty list, OR maybe you should cast item to be an integer:

{{ result.results[item |int].container.Config.Hostname }}

One option would be to output result in a debug statement before you try to use it, so you can look at its structure and then dereference it properly.

BTW this is guesswork. I haven’t read any doco or tested any of the above.

Regards, K.

---

<div class="post-metadata">

**Author:** ![abhay\_srivastava](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@abhay\_srivastava](https://forum.ansible.com/u/abhay_srivastava)\
**Post date:** [October 16, 2019, 3:31am UTC](https://forum.ansible.com/t/unable-to-copy-ansible-vriable-into-file/31470/3 "2019-10-16T03:31:39Z")

</div>

Thanks its work.
