# IndexError: list index out of range

**URL:** <https://forum.ansible.com/t/indexerror-list-index-out-of-range/17506>\
**Category:** Ansible Project\
**Created:** [February 12, 2015, 6:18am UTC](https://forum.ansible.com/t/indexerror-list-index-out-of-range/17506 "2015-02-12T06:18:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amol\_Shende](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Amol\_Shende](https://forum.ansible.com/u/Amol_Shende)\
**Post date:** [February 12, 2015, 6:18am UTC](https://forum.ansible.com/t/indexerror-list-index-out-of-range/17506/1 "2015-02-12T06:18:26Z")

</div>

Hi Everyone, I am using ansible since 2 months. It was working fine uptill now. But, now it is giving error to every ansible command.  
For Ex. I am running ping command it is giving following error

**ansible -vvvv 172.27.59.27 -m ping**

\<172.27.59.27\> ESTABLISH CONNECTION FOR USER: root  
\<172.27.59.27\> REMOTE\_MODULE ping  
\<172.27.59.27\> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=“/root/.ansible/cp/ansible-ssh-%h-%p-%r” -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 172.27.59.27 /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1423718954.13-54115388015450 && echo $HOME/.ansible/tmp/ansible-tmp-1423718954.13-54115388015450’  
172.27.59.27 | FAILED =\> Traceback (most recent call last):  
File “/usr/lib/python2.7/site-packages/ansible/runner/ **init**.py”, line 590, in \_executor  
exec\_rc = self.\_executor\_internal(host, new\_stdin)  
File “/usr/lib/python2.7/site-packages/ansible/runner/ **init**.py”, line 792, in \_executor\_internal  
return self.\_executor\_internal\_inner(host, self.module\_name, self.module\_args, inject, port, complex\_args=complex\_args)  
File “/usr/lib/python2.7/site-packages/ansible/runner/ **init**.py”, line 1025, in \_executor\_internal\_inner  
result = handler.run(conn, tmp, module\_name, module\_args, inject, complex\_args)  
File “/usr/lib/python2.7/site-packages/ansible/runner/action\_plugins/normal.py”, line 57, in run  
return self.runner.\_execute\_module(conn, tmp, module\_name, module\_args, inject=inject, complex\_args=complex\_args)  
File “/usr/lib/python2.7/site-packages/ansible/runner/ **init**.py”, line 475, in \_execute\_module  
tmp = self.\_make\_tmp\_path(conn)  
File “/usr/lib/python2.7/site-packages/ansible/runner/ **init**.py”, line 1267, in \_make\_tmp\_path  
result = self.\_low\_level\_exec\_command(conn, cmd, None, sudoable=False)  
File “/usr/lib/python2.7/site-packages/ansible/runner/ **init**.py”, line 1173, in \_low\_level\_exec\_command  
in\_data=in\_data)  
File “/usr/lib/python2.7/site-packages/ansible/runner/connection\_plugins/ssh.py”, line 291, in exec\_command  
not\_in\_host\_file = self.not\_in\_host\_file(self.host)  
File “/usr/lib/python2.7/site-packages/ansible/runner/connection\_plugins/ssh.py”, line 236, in not\_in\_host\_file  
if tokens[0].find(self.HASHED\_KEY\_MAGIC) == 0:  
**IndexError: list index out of range**

---

<div class="post-metadata">

**Author:** ![Daniel6](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@Daniel6](https://forum.ansible.com/u/Daniel6)\
**Post date:** [February 12, 2015, 10:44pm UTC](https://forum.ansible.com/t/indexerror-list-index-out-of-range/17506/2 "2015-02-12T22:44:04Z")

</div>

From the “not\_in\_host\_file” it sounds like possibly something on the ssh side. Are you able to ssh to 172.27.59.27 manually (either with a password or with the certificate that command is trying to use)?

Cheers,  
Daniel

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [February 13, 2015, 1:24am UTC](https://forum.ansible.com/t/indexerror-list-index-out-of-range/17506/3 "2015-02-13T01:24:02Z")

</div>

> Hi Everyone, I am using ansible since 2 months. It was working fine  
> uptill  
> now. But, now it is giving error to every ansible command.  
> For Ex. I am running ping command it is giving following error

[...]

> "/usr/lib/python2.7/site-packages/ansible/runner/connection\_plugins/ssh.py",  
> line 236, in not\_in\_host\_file  
> &nbsp;&nbsp;&nbsp;&nbsp;if tokens[0].find(self.HASHED\_KEY\_MAGIC) == 0:  
> \*IndexError: list index out of range\*

Something is wrong with your "~/.ssh/known\_hosts" file?

Giovanni

---

<div class="post-metadata">

**Author:** ![Amol\_Shende](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@Amol\_Shende](https://forum.ansible.com/u/Amol_Shende)\
**Post date:** [February 13, 2015, 10:14am UTC](https://forum.ansible.com/t/indexerror-list-index-out-of-range/17506/4 "2015-02-13T10:14:52Z")

</div>

Hi Giovanni ,  
Thanks for your valuable solution. I deleted all entries in known\_hosts file and it resolved my issue.

---

<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:** [February 13, 2015, 3:56pm UTC](https://forum.ansible.com/t/indexerror-list-index-out-of-range/17506/5 "2015-02-13T15:56:13Z")

</div>

A stacktrace is still a bug in our opinion, this PR [https://github.com/ansible/ansible/pull/10238](https://github.com/ansible/ansible/pull/10238) should skip bad data in the file.
