Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

ansible 2.4.2.0
config file = /Users/mdelagrange/.ansible.cfg
configured module search path = [u'/Users/mdelagrange/src/ops/ansible/library']
ansible python module location = /Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible
executable location = ./env/bin/ansible
python version = 2.7.12 (default, Jun 29 2016, 14:05:02) [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]

CONFIGURATION

ANSIBLE_SSH_CONTROL_PATH(/Users/mdelagrange/.ansible.cfg) = %(directory)s/%%h-%%

DEFAULT_HOST_LIST(/Users/mdelagrange/.ansible.cfg) = [u'/Users/mdelagrange/src/o

DEFAULT_MODULE_PATH(/Users/mdelagrange/.ansible.cfg) = [u'/Users/mdelagrange/src

DEFAULT_VAULT_PASSWORD_FILE(/Users/mdelagrange/.ansible.cfg) = /Users/mdelagrang

HOST_KEY_CHECKING(/Users/mdelagrange/.ansible.cfg) = False

OS / ENVIRONMENT

OS X

SUMMARY

The "include_role" task seems to result in infinite recursion.

STEPS TO REPRODUCE

Clone https://github.com/mdelagrange/ansible_include_role_bug

Run make test_2_4_2_0

- hosts: localhost
roles:
- test_role
post_tasks:
- include_role:
name: test_role

EXPECTED RESULTS

test_role is executed twice.

ACTUAL RESULTS

ansible-playbook 2.4.2.0
config file = /Users/mdelagrange/.ansible.cfg
configured module search path = [u'/Users/mdelagrange/src/ops/ansible/library']
ansible python module location = /Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible
executable location = ./env/bin/ansible-playbook
python version = 2.7.12 (default, Jun 29 2016, 14:05:02) [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]
Using /Users/mdelagrange/.ansible.cfg as config file
setting up inventory plugins
Parsed /Users/mdelagrange/src/ops/ansible/inventory/get-ec2-inv.sh inventory source with script plugin
Parsed /Users/mdelagrange/src/ops/ansible/inventory/riad3 inventory source with ini plugin
Parsed /Users/mdelagrange/src/ops/ansible/inventory/sch1 inventory source with ini plugin
Parsed /Users/mdelagrange/src/ops/ansible/inventory/sch3 inventory source with ini plugin
Parsed /Users/mdelagrange/src/ops/ansible/inventory/transit-vpc inventory source with ini plugin
Parsed /Users/mdelagrange/src/ops/ansible/inventory/windows inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc

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

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

TASK [Gathering Facts] *********************************************************
Using module file /Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/modules/system/setup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: mdelagrange
<127.0.0.1> EXEC /bin/sh -c 'echo ~ && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/mdelagrange/.ansible/tmp/ansible-tmp-1512514023.91-184937761254613 `" && echo ansible-tmp-1512514023.91-184937761254613="` echo /Users/mdelagrange/.ansible/tmp/ansible-tmp-1512514023.91-184937761254613 `" ) && sleep 0'
<127.0.0.1> PUT /var/folders/vn/kb09q_5s3s92r1gmv_5n1yfxfp9c16/T/tmpCFOhU4 TO /Users/mdelagrange/.ansible/tmp/ansible-tmp-1512514023.91-184937761254613/setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /Users/mdelagrange/.ansible/tmp/ansible-tmp-1512514023.91-184937761254613/ /Users/mdelagrange/.ansible/tmp/ansible-tmp-1512514023.91-184937761254613/setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/Users/mdelagrange/src/github/ansible_include_role_bug/env/bin/python2.7 /Users/mdelagrange/.ansible/tmp/ansible-tmp-1512514023.91-184937761254613/setup.py; rm -rf "/Users/mdelagrange/.ansible/tmp/ansible-tmp-1512514023.91-184937761254613/" > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [test_role : debug] *******************************************************
task path: /Users/mdelagrange/src/github/ansible_include_role_bug/roles/test_role/tasks/main.yml:1
ok: [localhost] => {
"msg": "foo"
}
META: ran handlers

TASK [include_role] ************************************************************
task path: /Users/mdelagrange/src/github/ansible_include_role_bug/test-playbook.yml:5
the full traceback was:

Traceback (most recent call last):
File "./env/bin/ansible-playbook", line 106, in <module>
exit_code = cli.run()
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/cli/playbook.py", line 130, in run
results = pbex.run()
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 154, in run
result = self._tqm.run(play=play)
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 290, in run
play_return = strategy.run(iterator, play_context)
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/plugins/strategy/linear.py", line 292, in run
results += self._wait_on_pending_results(iterator)
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/plugins/strategy/__init__.py", line 586, in _wait_on_pending_results
results = self._process_pending_results(iterator)
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/plugins/strategy/__init__.py", line 548, in _process_pending_results
self._tqm.send_callback('v2_runner_on_ok', task_result)
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 367, in send_callback
new_args.append(arg.clean_copy())
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/executor/task_result.py", line 109, in clean_copy
result._result = deepcopy(self._result)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)

[~2000 lines omitted]

File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
state = deepcopy(state, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
y = copier(x, memo)
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 230, in _deepcopy_list
y.append(deepcopy(a, memo))
File "/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 182, in deepcopy
rv = reductor(2)
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/inventory/host.py", line 34, in __getstate__
return self.serialize()
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/inventory/host.py", line 59, in serialize
groups.append(group.serialize())
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/inventory/group.py", line 55, in serialize
parent_groups.append(parent.serialize())
File "/Users/mdelagrange/src/github/ansible_include_role_bug/env/lib/python2.7/site-packages/ansible/inventory/group.py", line 55, in serialize
parent_groups.append(parent.serialize())
RuntimeError: maximum recursion depth exceeded

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

include and include_role

ANSIBLE VERSION

ansible 2.2.1.0
config file =
configured module search path = Default w/o overrides

CONFIGURATION

No change

OS / ENVIRONMENT

Red Hat Enterprise Linux Server release 6.6

SUMMARY

Nested include leads to the following error:

Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <type 'exceptions.RuntimeError'> ignored
ERROR! Unexpected Exception: maximum recursion depth exceeded

The error occurs with real playbooks with a mix of 5 nested include_role and include

playbook:

role

include_role

include_role

include_role

include

include

It's reproducible with a playbook with 12 nested include.

STEPS TO REPRODUCE

Playbook:
- hosts: localhost
roles:
- role1

role1/tasks/main.yml:
---
- name: "include: r1t1.yml"
include: r1t1.yml

role1/tasks/r1t1.yml:
- name: "include r1t2"
include: r1t2.yml

and so on up to role1/tasks/r1t12.yml:
---
- debug: msg="r1t12"

EXPECTED RESULTS

Playbook runs successfully.

ACTUAL RESULTS

ansible-playbook -vv test.yml
No config file found; using defaults
[WARNING]: Host file not found: /etc/ansible/hosts

[WARNING]: provided hosts list is empty, only localhost is available

statically included: /home/user/test/role1/tasks/r1t1.yml
statically included: /home/user/test/role1/tasks/r1t2.yml
statically included: /home/user/test/role1/tasks/r1t3.yml
statically included: /home/user/test/role1/tasks/r1t4.yml
statically included: /home/user/test/role1/tasks/r1t5.yml
statically included: /home/user/test/role1/tasks/r1t6.yml
statically included: /home/user/test/role1/tasks/r1t7.yml
statically included: /home/user/test/role1/tasks/r1t8.yml
statically included: /home/user/test/role1/tasks/r1t9.yml
statically included: /home/user/test/role1/tasks/r1t10.yml
statically included: /home/user/test/role1/tasks/r1t11.yml
statically included: /home/user/test/role1/tasks/r1t12.yml

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

PLAY [localhost] ***************************************************************
Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <type 'exceptions.RuntimeError'> ignored
ERROR! Unexpected Exception: maximum recursion depth exceeded

ansible-include-issue.zip