Repository: ansible/ansible

Issue:
Task name is overridden by include_role, and is not evaluated in output
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY
<!--- Explain the problem briefly -->
When using `include_role`, the `name` parameter given to it appears to override the `name` parameter given to the task itself. Additionally, if jinja2 was being used to determine which role to include, that is not evaluated and is printed raw, which is not useful to an observer.

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path-->
include_role

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.6.1
```

##### CONFIGURATION
<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).-->

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.-->
Red Hat Enterprise Linux Server release 7.4 (Maipo)

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

<!--- Paste example playbooks or commands between quotes below -->
Playbook
```yaml
- name: "test"
  hosts: localhost
  gather_facts: no
  connection: local

  vars:
    role_type: a

  tasks:
    - name: Role inclusion test
      include_role:
        name: "role-{{ role_type }}"
```
roles/role-a/tasks/main.yml
```yaml
---
- debug: msg="This is Role A"
```
<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
```
PLAY [test] ********************************************************************

TASK [Role inclusion test] *****************************************************

TASK [role-a : debug] **********************************************************
[...]
```
Or, less preferably:
```
PLAY [test] ********************************************************************

TASK [include_role : role-a *************************************

TASK [role-a : debug] **********************************************************
[...]
```
##### ACTUAL RESULTS
```
PLAY [test] ********************************************************************

TASK [include_role : role-{{ role_type }}] *************************************

TASK [role-a : debug] **********************************************************
[...]
```



Discussion:
Files identified in the description:
* [lib/ansible/playbook/role/include.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/playbook/role/include.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->

Resolving patch:
diff --git a/lib/ansible/playbook/role_include.py b/lib/ansible/playbook/role_include.py
--- a/lib/ansible/playbook/role_include.py
+++ b/lib/ansible/playbook/role_include.py
@@ -68,7 +68,7 @@ def __init__(self, block=None, role=None, task_include=None):
 
     def get_name(self):
         ''' return the name of the task '''
-        return "%s : %s" % (self.action, self._role_name)
+        return self.name or "%s : %s" % (self.action, self._role_name)
 
     def get_block_list(self, play=None, variable_manager=None, loader=None):
 


Test patch: