Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

import_role

ANSIBLE VERSION

ansible 2.4.2.0

CONFIGURATION

OS / ENVIRONMENT

python version = 2.7.14 (default, Jan 17 2018, 14:28:32) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]

SUMMARY

Using import_role inside handler task fails while other tasks work fine.

STEPS TO REPRODUCE

test.yml

- hosts: wasservers
tasks:
- name: Tester Role
import_role: name=tester

roles/tester/tasks/main.yml

---
- name: Testing Handler
command: pwd
notify:
- TEST_HANDLER_1
- TEST_HANDLER_2

roles/tester/handlers/main.yml

---
- name: TEST_HANDLER_1
debug: msg="TEST_HANDLER_1 Called"

- name: TEST_HANDLER_2
import_role: name=test_role

roles/test_role/tasks/main.yml

---
- name: Inside Test Handler Role
debug: msg="Called through TEST_HANDLER_2 "

EXPECTED RESULTS

RUNNING HANDLER [tester : TEST_HANDLER_1] *************************************************************************************************************************************************************************

ok: [192.168.124.85] => {

"msg": "TEST_HANDLER_1 Called"

}

RUNNING HANDLER [tester : TEST_HANDLER_2] *************************************************************************************************************************************************************************

TASK [test_role : Inside Test Handler Role] ***********************************************************************************************************************************************************************

ok: [192.168.124.85] => {

"msg": "Called through TEST_HANDLER_2 "

}

ACTUAL RESULTS

PLAYBOOK: test.yml ************************************************************************************************************************************************************************************************
1 plays in test.yml

PLAY [wasservers] *************************************************************************************************************************************************************************************************
ERROR! Unexpected Exception, this is probably a bug: 'Task' object has no attribute 'listen'
the full traceback was:

Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 106, in <module>
exit_code = cli.run()
File "/usr/lib/python2.7/site-packages/ansible/cli/playbook.py", line 130, in run
results = pbex.run()
File "/usr/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 154, in run
result = self._tqm.run(play=play)
File "/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 253, in run
self._initialize_notified_handlers(new_play)
File "/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 142, in _initialize_notified_handlers
self.update_handler_list(handler_list)
File "/usr/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 149, in update_handler_list
if handler.listen:
AttributeError: 'Task' object has no attribute 'listen'

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

ansible-inventory

ANSIBLE VERSION

2.4.1.0-2.4.3.0

CONFIGURATION

OS / ENVIRONMENT

redhat linux

SUMMARY

ansible-inventory script cannot output inventory when it have yaml files with embedded ecnrypted variables

STEPS TO REPRODUCE

setup simple inventory with yaml file containing embedded encrypted value

run ansible-inventory --list

https://gist.github.com/kudrevatykh/39875c9939d7248cd91f7bd1155a22ae

EXPECTED RESULTS

correct json that can be used as inventory

ACTUAL RESULTS

exception when output is json and not valid output when yaml (with values &id001, *id001 instead of real value)

ERROR! Unexpected Exception, this is probably a bug: u'111' is not JSON serializable
the full traceback was:

Traceback (most recent call last):
File "/home/kudrale/ansible-2.4.1.0/bin/ansible-inventory", line 106, in <module>
exit_code = cli.run()
File "/home/kudrale/ansible-2.4.1.0/lib/ansible/cli/inventory.py", line 157, in run
results = self.dump(results)
File "/home/kudrale/ansible-2.4.1.0/lib/ansible/cli/inventory.py", line 174, in dump
results = json.dumps(stuff, sort_keys=True, indent=4)
File "/usr/lib64/python2.7/json/__init__.py", line 250, in dumps
sort_keys=sort_keys, **kw).encode(obj)
File "/usr/lib64/python2.7/json/encoder.py", line 209, in encode
chunks = list(chunks)
File "/usr/lib64/python2.7/json/encoder.py", line 434, in _iterencode
for chunk in _iterencode_dict(o, _current_indent_level):
File "/usr/lib64/python2.7/json/encoder.py", line 408, in _iterencode_dict
for chunk in chunks:
File "/usr/lib64/python2.7/json/encoder.py", line 408, in _iterencode_dict
for chunk in chunks:
File "/usr/lib64/python2.7/json/encoder.py", line 408, in _iterencode_dict
for chunk in chunks:
File "/usr/lib64/python2.7/json/encoder.py", line 408, in _iterencode_dict
for chunk in chunks:
File "/usr/lib64/python2.7/json/encoder.py", line 442, in _iterencode
o = _default(o)
File "/usr/lib64/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: u'111' is not JSON serializable