# playbook fails testing connection from loadbalancer (nginix) to 2 backend webhosts (apache2)

**URL:** <https://forum.ansible.com/t/playbook-fails-testing-connection-from-loadbalancer-nginix-to-2-backend-webhosts-apache2/22334>\
**Category:** Ansible Project\
**Tags:** ubuntu, aws\
**Created:** [August 20, 2016, 11:33pm UTC](https://forum.ansible.com/t/playbook-fails-testing-connection-from-loadbalancer-nginix-to-2-backend-webhosts-apache2/22334 "2016-08-20T23:33:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Lovato](https://avatars.discourse-cdn.com/v4/letter/j/8e7dd6/32.png) [@James\_Lovato](https://forum.ansible.com/u/James_Lovato)\
**Post date:** [August 20, 2016, 11:33pm UTC](https://forum.ansible.com/t/playbook-fails-testing-connection-from-loadbalancer-nginix-to-2-backend-webhosts-apache2/22334/1 "2016-08-20T23:33:27Z")

</div>

The test to the loadbalancer itself never fails, and serves the same content as the websites (although host and metadata are a bit different), and I can’t for the life of me figure out the disconnect.  
If someone can point me in the right direction it would be appreciated.

All hosts are ubuntu 16.04.01 LTS  
hostnames:  
loadbalancer - Ansible-nginx  
webcluster - AnsibleWeb, AnsibleWeb2

All AWS EC2 instances

The loadbalancer lines in my status playbook:

- hosts: loadbalancer  
tasks:

- name: verify backend index response  
uri: url=http://{{item}} return\_content=yes  
with\_items: ‘{{groups.webcluster}}’  
register: app\_index

- fail: msg=“index failed to return content”  
when: “‘Hello, from sunny {{item.item}}!’ not in item.content”  
with\_items: “{{app\_index.results}}”

Output of the play before it stops:

PLAY [loadbalancer] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [Ansible-nginx]

TASK [verify backend index response] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [Ansible-nginx] =\> (item=AnsibleWeb)  
ok: [Ansible-nginx] =\> (item=AnsibleWeb2)

TASK [fail] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [Ansible-nginx] (item={ **u** ’ **status’: 200** , u’content\_length’: u’35’, ‘\_ansible\_item\_result’: True, u’date’: u’Sat, 20 Aug 2016 23:26:21 GMT’, ‘\_ansible\_no\_log’: False, u’url’: u’[http://AnsibleWeb](http://AnsibleWeb)’, u’changed’: False, u’server’: u’Apache/2.4.18 (Ubuntu)‘, **u’content’: u’Hello, from sunny ip-172-31-30-54!\n’** , ‘item’: u’AnsibleWeb’, u’connection’: u’close’, u’content\_type’: u’text/html; charset=utf-8’, ‘invocation’: {‘module\_name’: u’uri’, u’module\_args’: {u’directory\_mode’: None, u’force’: False, u’remote\_src’: None, u’follow\_redirects’: u’safe’, u’body\_format’: u’raw’, u’owner’: None, u’follow’: False, u’group’: None, u’use\_proxy’: True, u’setype’: None, u’content’: None, u’serole’: None, u’status\_code’: [200], u’return\_content’: True, u’method’: u’GET’, u’body’: None, u’url\_username’: None, u’src’: None, u’dest’: None, u’selevel’: None, u’force\_basic\_auth’: False, u’removes’: None, u’http\_agent’: u’ansible-httpget’, u’regexp’: None, u’url\_password’: None, u’url’: u’[http://AnsibleWeb](http://AnsibleWeb)’, u’backup’: None, u’seuser’: None, u’creates’: None, u’headers’: {}, u’delimiter’: None, u’mode’: None, u’timeout’: 30, u’validate\_certs’: True}}, u’msg’: u’OK (35 bytes)‘, u’redirected’: False}) =\> {“failed”: true, “item”: {“changed”: false, “connection”: “close”, **“content”: “Hello, from sunny ip-172-31-30-54!\n”,** “content\_length”: “35”, “content\_type”: “text/html; charset=utf-8”, “date”: “Sat, 20 Aug 2016 23:26:21 GMT”, “invocation”: {“module\_args”: {“backup”: null, “body”: null, “body\_format”: “raw”, “content”: null, “creates”: null, “delimiter”: null, “dest”: null, “directory\_mode”: null, “follow”: false, “follow\_redirects”: “safe”, “force”: false, “force\_basic\_auth”: false, “group”: null, “headers”: {}, “http\_agent”: “ansible-httpget”, “method”: “GET”, “mode”: null, “owner”: null, “regexp”: null, “remote\_src”: null, “removes”: null, “return\_content”: true, “selevel”: null, “serole”: null, “setype”: null, “seuser”: null, “src”: null, “status\_code”: [200], “timeout”: 30, “url”: “[http://AnsibleWeb](http://AnsibleWeb)”, “url\_password”: null, “url\_username”: null, “use\_proxy”: true, “validate\_certs”: true}, “module\_name”: “uri”}, “item”: “AnsibleWeb”, “msg”: “OK (35 bytes)”, “redirected”: false, “server”: “Apache/2.4.18 (Ubuntu)”, “status”: 200, “url”: “[http://AnsibleWeb](http://AnsibleWeb)”}, “msg”: “index failed to return content”}  
failed: [Ansible-nginx] (item={ **u’status’: 200,** u’content\_length’: u’35’, ‘\_ansible\_item\_result’: True, u’date’: u’Sat, 20 Aug 2016 23:26:21 GMT’, ‘\_ansible\_no\_log’: False, u’url’: u’[http://AnsibleWeb2](http://AnsibleWeb2)’, u’changed’: False, u’server’: u’Apache/2.4.18 (Ubuntu)‘, **u’content’: u’Hello, from sunny ip-172-31-24-83!\n’,** ‘item’: u’AnsibleWeb2’, u’connection’: u’close’, u’content\_type’: u’text/html; charset=utf-8’, ‘invocation’: {‘module\_name’: u’uri’, u’module\_args’: {u’directory\_mode’: None, u’force’: False, u’remote\_src’: None, u’follow\_redirects’: u’safe’, u’body\_format’: u’raw’, u’owner’: None, u’follow’: False, u’group’: None, u’use\_proxy’: True, u’setype’: None, u’content’: None, u’serole’: None, u’status\_code’: [200], u’return\_content’: True, u’method’: u’GET’, u’body’: None, u’url\_username’: None, u’src’: None, u’dest’: None, u’selevel’: None, u’force\_basic\_auth’: False, u’removes’: None, u’http\_agent’: u’ansible-httpget’, u’regexp’: None, u’url\_password’: None, u’url’: u’[http://AnsibleWeb2](http://AnsibleWeb2)’, u’backup’: None, u’seuser’: None, u’creates’: None, u’headers’: {}, u’delimiter’: None, u’mode’: None, u’timeout’: 30, u’validate\_certs’: True}}, u’msg’: u’OK (35 bytes)‘, u’redirected’: False}) =\> {“failed”: true, “item”: {“changed”: false, “connection”: “close”, **“content”: “Hello, from sunny ip-172-31-24-83!\n”,** “content\_length”: “35”, “content\_type”: “text/html; charset=utf-8”, “date”: “Sat, 20 Aug 2016 23:26:21 GMT”, “invocation”: {“module\_args”: {“backup”: null, “body”: null, “body\_format”: “raw”, “content”: null, “creates”: null, “delimiter”: null, “dest”: null, “directory\_mode”: null, “follow”: false, “follow\_redirects”: “safe”, “force”: false, “force\_basic\_auth”: false, “group”: null, “headers”: {}, “http\_agent”: “ansible-httpget”, “method”: “GET”, “mode”: null, “owner”: null, “regexp”: null, “remote\_src”: null, “removes”: null, “return\_content”: true, “selevel”: null, “serole”: null, “setype”: null, “seuser”: null, “src”: null, “status\_code”: [200], “timeout”: 30, “url”: “[http://AnsibleWeb2](http://AnsibleWeb2)”, “url\_password”: null, “url\_username”: null, “use\_proxy”: true, “validate\_certs”: true}, “module\_name”: “uri”}, “item”: “AnsibleWeb2”, “msg”: “OK (35 bytes)”, “redirected”: false, “server”: “Apache/2.4.18 (Ubuntu)”, “status”: 200, “url”: “[http://AnsibleWeb2](http://AnsibleWeb2)”}, “msg”: “index failed to return content”}

NO MORE HOSTS LEFT \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
[WARNING]: Could not create retry file ‘stack\_status.retry’. [Errno 2] No such  
file or directory: ‘’

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
Ansible-nginx : ok=5 changed=1 unreachable=0 failed=1  
AnsibleControl : ok=3 changed=0 unreachable=0 failed=0  
AnsibleDB : ok=3 changed=1 unreachable=0 failed=0  
AnsibleWeb : ok=3 changed=1 unreachable=0 failed=0  
AnsibleWeb2 : ok=3 changed=1 unreachable=0 failed=0

---

<div class="post-metadata">

**Author:** ![Robert\_Williams1](https://avatars.discourse-cdn.com/v4/letter/r/bc8723/32.png) [@Robert\_Williams1](https://forum.ansible.com/u/Robert_Williams1)\
**Post date:** [July 24, 2017, 5:09pm UTC](https://forum.ansible.com/t/playbook-fails-testing-connection-from-loadbalancer-nginix-to-2-backend-webhosts-apache2/22334/2 "2017-07-24T17:09:27Z")

</div>

I am trying to figure out the same issue. Please let me know if you have it resolved.

Thanks,

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [July 25, 2017, 3:16am UTC](https://forum.ansible.com/t/playbook-fails-testing-connection-from-loadbalancer-nginix-to-2-backend-webhosts-apache2/22334/3 "2017-07-25T03:16:06Z")

</div>

from what i see {{ item.item }} would expand to 'AnsibleWeb' when the  
content actually has "ip-172-31-24-83!" hence it fails. so i think  
the condition would be  
when: "'Hello, from sunny {{hostvars[item.item][ansible\_hostname]}}!'  
not in item.content"  
you might need a play to collect facts from the web group.
