From 240b060c02ee08fc6914a50398bb52e2b36b722c Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Mon, 30 Apr 2018 14:41:13 -0500 Subject: [PATCH] Use the computed role name instead of 'role'. Fixes #38838 (#39516) --- lib/ansible/playbook/included_file.py | 2 +- test/integration/inventory | 2 +- .../include_import/role/test_include_role.yml | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py index e0e09373ca6..a2261fb39ee 100644 --- a/lib/ansible/playbook/included_file.py +++ b/lib/ansible/playbook/included_file.py @@ -160,7 +160,7 @@ class IncludedFile: from_key = from_arg.replace('_from', '') new_task._from_files[from_key] = templar.template(include_variables[from_arg]) - inc_file = IncludedFile("role", include_variables, new_task, is_role=True) + inc_file = IncludedFile(role_name, include_variables, new_task, is_role=True) try: pos = included_files.index(inc_file) diff --git a/test/integration/inventory b/test/integration/inventory index 5c3fee6a787..55cd4bc1137 100644 --- a/test/integration/inventory +++ b/test/integration/inventory @@ -1,6 +1,6 @@ [local] testhost ansible_ssh_host=127.0.0.1 ansible_connection=local host_var_role_name=role3 -testhost2 ansible_ssh_host=127.0.0.1 ansible_connection=local +testhost2 ansible_ssh_host=127.0.0.1 ansible_connection=local host_var_role_name=role2 # For testing delegate_to testhost3 ansible_ssh_host=127.0.0.3 testhost4 ansible_ssh_host=127.0.0.4 diff --git a/test/integration/targets/include_import/role/test_include_role.yml b/test/integration/targets/include_import/role/test_include_role.yml index c0be84c6ba7..f9ea65a6e81 100644 --- a/test/integration/targets/include_import/role/test_include_role.yml +++ b/test/integration/targets/include_import/role/test_include_role.yml @@ -1,5 +1,5 @@ - name: Test include_role - hosts: testhost + hosts: testhost,testhost2 vars: run_role: yes @@ -85,10 +85,27 @@ include_role: name: "{{ role_name }}" + - name: wipe role results + set_fact: + _role2_result: ~ + _role3_result: ~ + - name: Test using a host variable for role name include_role: name: "{{ host_var_role_name }}" + - name: assert that host varible for role name calls 2 diff roles + assert: + that: + - _role2_result is not none + when: inventory_hostname == 'testhost2' + + - name: assert that host varible for role name calls 2 diff roles + assert: + that: + - _role3_result is not none + when: inventory_hostname == 'testhost' + - name: Pass variable to role include_role: name: role1