# Exception: host not found issue with v1.8.2

**URL:** <https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196>\
**Category:** Ansible Project\
**Created:** [January 6, 2015, 6:25pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196 "2015-01-06T18:25:03Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [January 6, 2015, 6:25pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/1 "2015-01-06T18:25:03Z")

</div>

Hi,

Having problems with 1.8.2

I believe the problem is similar to

[https://github.com/ansible/ansible/issues/9828](https://github.com/ansible/ansible/issues/9828)

[http://serverfault.com/questions/652746/ansible-exception-host-not-found-item](http://serverfault.com/questions/652746/ansible-exception-host-not-found-item)

- name: Create ansible environmental debug  
action: template src=dumpall.j2 dest={{ debug\_dir }}/ansible-{{ playbook }}.{{ ansible\_date\_time.date}}.txt

TASK: [openbet/env-debug | Create ansible environmental debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [ec2-test-boapp02] =\> {‘msg’: ‘Exception: host not found: admin\_login\_key’, ‘failed’: True}

The posts recommend patching l\*\*ib/ansible/runner/\*\ ***init.py.** I don’t have access control on the box to patch the version and can only take from EPEL

What’s the best way to fix this?

1.8.2 is the only version that’s available. Is there a workaround I can make or is there a release date for 1.8.3?

EPEL was on 1.8.1 which broke our build with variable precedence. Now this. I’m a tad stuck at the moment

I would really appreciate any help

Many thanks

James

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [January 6, 2015, 6:32pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/2 "2015-01-06T18:32:32Z")

</div>

Are you able to test whether that fixes your issue? Are you able to pull from epel-testing into your production environment? I could talk to the epel maintainer about pulling that patch into the epel package which may help you out. But there have been some other issues opened with similar symptoms that haven’t been fixed by that patch so I’d like to confirm that this would fix your issue first.

-Toshio

---

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [January 6, 2015, 6:51pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/3 "2015-01-06T18:51:14Z")

</div>

Hi,

Thanks for the quick response. I will have a chat with our OPs guys first thing tomorrow and get them to patch lib/ansible/runner/init.py and see if it fixed it.

Will let you know soon as I find out.

Thanks

---

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [January 7, 2015, 2:31pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/4 "2015-01-07T14:31:57Z")

</div>

Hi,

I have applied the patch and its producing the same error. I will create a example to demonstrate the problem

It isn’t the same as the delegate\_to issue though does seem to relate to template handling with groups / group\_names in templates

James

---

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [January 7, 2015, 2:46pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/5 "2015-01-07T14:46:35Z")

</div>

The issue actually seems to be with the hostvars.

Ive knocked up a cut down version that emulates this

[https://github.com/jamesdmorgan/ansible1.8.1\_template\_issue](https://github.com/jamesdmorgan/ansible1.8.1_template_issue)

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost]

TASK: [env-debug | Create debug directory] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> (item=./debug\_log)

TASK: [env-debug | Create ansible environmental debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost] =\> {‘msg’: ‘Exception: host not found: ansible\_connection’, ‘failed’: True}  
fatal: [localhost] =\> {‘msg’: ‘Exception: host not found: ansible\_connection’, ‘failed’: True}

FATAL: all hosts have already failed – aborting

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
to retry, use: --limit @/home/jmorgan/site.retry

localhost : ok=2 changed=0 unreachable=1 failed=0

---

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [January 7, 2015, 2:49pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/6 "2015-01-07T14:49:17Z")

</div>

Issue is in 1.8.2, I misnamed the repo. Apologies

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [January 7, 2015, 7:12pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/7 "2015-01-07T19:12:15Z")

</div>

I'm not getting the host\_not\_found error in either 1.8.2 or devel but  
I suspect that I need something specific in my inventory file to  
reproduce this? Are you able to post what that should be?

-Toshio

---

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [January 8, 2015, 1:46pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/8 "2015-01-08T13:46:53Z")

</div>

Hi,

If you look at the git example I created

[https://github.com/jamesdmorgan/ansible1.8.1\_template\_issue](https://github.com/jamesdmorgan/ansible1.8.1_template_issue)

.  
├── debug\_log  
├── README.md  
├── roles  
│ └── env-debug  
│ ├── defaults  
│ │ └── main.yml  
│ ├── tasks  
│ │ └── main.yml  
│ └── templates  
│ └── dumpall.j2  
└── site.yml

I just ran

ansible-playbook --connection=local site.yml

The issue seems to be around the template which contains

**{{ hostvars | to\_nice\_json }}**

If I remove this it works fine.

Hope that helps

James

---

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [January 8, 2015, 2:09pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/9 "2015-01-08T14:09:32Z")

</div>

Ok im confused now.

I’ve just spun up a docker container and isolated it and it doesn’t error on v1.8.2

I will have to do more debugging to see what is in the environment / inventory on our dev servers that could cause this.

James

---

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [January 9, 2015, 9:09am UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/10 "2015-01-09T09:09:11Z")

</div>

I have done some digging and there seems to be a problem with **to\_nice\_json**.

if I use

-{{ hostvars | **to\_nice\_json** }}

it breaks

if I use

-{{ hostvars | **to\_json** }}

It works correctly

```auto
def to_json(a, *args, **kw):
    ''' Convert the value to JSON '''
    return json.dumps(a, *args, **kw)

def to_nice_json(a, *args, **kw):
    '''Make verbose, human readable JSON'''
    return json.dumps(a, indent=4, sort_keys=True, *args, **kw)

```

It does look like it uses a different encoder under the hood if indent & sorting is enabled

[https://sourcegraph.com/hg.python.org/cpython@default/.PipPackage/Python/.def/json/dumps/cls?\_codeview=1](https://sourcegraph.com/hg.python.org/cpython@default/.PipPackage/Python/.def/json/dumps/cls?_codeview=1)

# cached encoder

if (not skipkeys and ensure\_ascii and  
check\_circular and allow\_nan and  
cls is None and indent is None and separators is None and  
default is None and not sort\_keys and not kw):  
return \_default\_encoder.encode(obj)  
if cls is None:  
cls = JSONEncoder  
return cls(  
skipkeys=skipkeys, ensure\_ascii=ensure\_ascii,  
check\_circular=check\_circular, allow\_nan=allow\_nan, indent=indent,  
separators=separators, default=default, sort\_keys=sort\_keys,  
\*\*kw).encode(obj)

---

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [January 9, 2015, 9:11am UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/11 "2015-01-09T09:11:52Z")

</div>

Dev environments use Python 2.6.6  
Docket has Python 2.7.3

That could well be the root of my issue and why you are unable to reproduce and why I can’t on docker

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [January 11, 2015, 9:33pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/12 "2015-01-11T21:33:33Z")

</div>

Had a chance to try using your repo on CentOS6 (with python-2.6.6) and  
I can confirm that ansible-1.8.2 has this problem but ansible devel  
does not. Going to try to track down the commit that causes this and  
whether it's easy to isolate the patch to fix it.

-Toshio

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [January 11, 2015, 9:45pm UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/13 "2015-01-11T21:45:04Z")

</div>

Mmmm.... one big correction -- It does not work with current devel (I  
was testing with a \*really\* old checkout before). So there's another,  
unaddressed bug here...

-Toshio

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [January 12, 2015, 12:16am UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/14 "2015-01-12T00:16:50Z")

</div>

Commit where this problem starts:  
29d41bb789383c3ff59269b28877ea0f270f5861 however, I don't think this  
is a bad commit. I think it's just exposing a bug elsewhere.

Where that elsewhere is... it looks to me like the json library in  
python2.6's stdlib has a bug that's causing this to fail. I haven't  
found a bug report in python or simplejson's issue trackers that  
points out where they may have fixed this specifically. I have found a  
commit where upstream python synced changes from simplejson-2.0.9  
(python2.6's json looks to have been based on simplejson 1.9).  
Delving into simplejson's code, I found that this commit fixed this  
issue: [https://github.com/simplejson/simplejson/commit/2afcca8635bb0adce45bcff7c069f320c82eb9f8#diff-436b24490ceb0883d559805a466865c5](https://github.com/simplejson/simplejson/commit/2afcca8635bb0adce45bcff7c069f320c82eb9f8#diff-436b24490ceb0883d559805a466865c5)

That appears to have been part of an optimization effort rather than a bugfix...

Where does that leave us.... To work around your bug on EPEL6, I  
think I can get the EPEL package to include a small patch to prefer  
simplejson over json in filter\_plugin/core.py. Not sure if I can  
also have ansible in epel6 start Requiring python-simplejson but even  
if I can't you can simply install it on your RHEL6 hosts. Between  
those two things, that should fix this particular issue for you.

For upstream ansible code, the answer isn't quite so simple. I  
haven't tracked down precisely what it is about your test that's  
breaking (other than it's to\_nice\_json) and we probably don't want to  
force everyone to install simplejson. So I'm not sure what precisely  
we want to do. Perhaps, something like this in to\_nice\_json():

if sys.version\_info \< (2, 7):  
&nbsp;&nbsp;&nbsp;&nbsp;try:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;import simplejson as json  
&nbsp;&nbsp;&nbsp;&nbsp;except ImportError:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return to\_json()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Or raise an informative error?

I'll talk to a few other people about what they'd like the fallback  
code to do in this case.

-Toshio

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [January 12, 2015, 4:15am UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/15 "2015-01-12T04:15:08Z")

</div>

Okay, update of ansible for epel6 has been submitted:  
[https://admin.fedoraproject.org/updates/ansible-1.8.2-3.el6](https://admin.fedoraproject.org/updates/ansible-1.8.2-3.el6) If you're  
interested in testing it you should be able to download directly from  
Fedora's buildsystem (there's a link in the update). The Fedora/EPEL  
workflow pushes builds to the updates-testing repository first. And  
after a few weeks into the main updates repo.

Hope that helps!  
-Toshio

---

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [January 12, 2015, 10:33am UTC](https://forum.ansible.com/t/exception-host-not-found-issue-with-v1-8-2/17196/16 "2015-01-12T10:33:02Z")

</div>

Hi,

Thanks so much for looking into this. Much appreciated.

I’ll get 1.8.2-3.el6 tested.

Cheers!

James
