{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/12280","labels_url":"https://api.github.com/repos/ansible/ansible/issues/12280/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/12280/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/12280/events","html_url":"https://github.com/ansible/ansible/issues/12280","id":105387674,"number":12280,"title":"Environment variables are not recognized in task name","user":{"login":"mclate","id":2183014,"avatar_url":"https://avatars.githubusercontent.com/u/2183014?v=3","gravatar_id":"","url":"https://api.github.com/users/mclate","html_url":"https://github.com/mclate","followers_url":"https://api.github.com/users/mclate/followers","following_url":"https://api.github.com/users/mclate/following{/other_user}","gists_url":"https://api.github.com/users/mclate/gists{/gist_id}","starred_url":"https://api.github.com/users/mclate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mclate/subscriptions","organizations_url":"https://api.github.com/users/mclate/orgs","repos_url":"https://api.github.com/users/mclate/repos","events_url":"https://api.github.com/users/mclate/events{/privacy}","received_events_url":"https://api.github.com/users/mclate/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/bug_report","name":"bug_report","color":"fbca04"},{"url":"https://api.github.com/repos/ansible/ansible/labels/P3","name":"P3","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-08T14:02:12Z","updated_at":"2015-09-08T14:28:37Z","closed_at":null,"body":"##### Issue Type:\r\n\r\nBug report\r\n\r\n##### Ansible Version:\r\n\r\n```\r\nansible 1.9.3\r\n  configured module search path = /usr/share/ansible\r\n```\r\n\r\n##### Ansible Configuration:\r\n\r\nNo extra changes applied\r\n\r\n##### Environment:\r\n\r\nN/A\r\n\r\n##### Summary:\r\n\r\nIn role, when variable is substituted into task name, if one is taken from role invocation (like `{role: role, variable: value}`), it is substituted correctly into task name (`- name: Task {{variable}}` results in `Task value`), however, if variable is not provided in role definition but provided in any other way (such as playbook invocation argument), it is not recognized: mentioned above task name results in `Task {{variable}}`. However, variable itself is recognized and substituted correctly in task details (see \"Steps To Reproduce\" for details)\r\n\r\n##### Steps To Reproduce:\r\n\r\n1. Create playbook:\r\n```yaml\r\n- hosts: all\r\n- roles:\r\n    - role: my_role\r\n```\r\n2. Create role `my_role`:\r\n```yaml\r\n- name: Debug {{ variable1 }}\r\n  debug:\r\n      var: \"{{ variable1 }}\"\r\n```\r\n3. Run playbook as `ansible-playbook playbook.yml -e variable1=value1`\r\n\r\n##### Expected Results:\r\n\r\n```ansible\r\nTASK: [my_role | Debug value1] ************************************************\r\nok: [host1] => {\r\n    \"var\": {\r\n        \"variable1\": \"value1\"\r\n    }\r\n}\r\n```\r\n\r\n##### Actual Results:\r\n\r\n```\r\nTASK: [my_role | Debug {{ variable1 }}] ************************************************\r\nok: [host1] => {\r\n    \"var\": {\r\n        \"variable1\": \"value1\"\r\n    }\r\n}\r\n```\r\n\r\nAs you can see, variable is correctly substituted in debug statement, but is not recognized in task name.\r\n\r\nHowever, if we replace role invocation as:\r\n\r\n```yaml\r\n- hosts: all\r\n- roles:\r\n    - role: my_role\r\n      variable1: \"{{ variable1 | default('default') }}\"\r\n```\r\n\r\nWe receive expected result. (`default('default')` is used because in case if variable is not defined we will receive recurcive loop when templating the variable)\r\n\r\nAlso, if we replace task name as (without `variable1` definition in role invocation):\r\n```yaml\r\n- name: Debug {{ variable1 | default('default') }}\r\n  debug:\r\n      var: \"{{ variable1 }}\"\r\n```\r\n\r\nwe get \r\n\r\n```ansible\r\nTASK: [my_role | Debug default] ************************************************\r\nok: [host1] => {\r\n    \"var\": {\r\n        \"variable1\": \"value1\"\r\n    }\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/138581695","html_url":"https://github.com/ansible/ansible/issues/12280#issuecomment-138581695","issue_url":"https://api.github.com/repos/ansible/ansible/issues/12280","id":138581695,"user":{"login":"mclate","id":2183014,"avatar_url":"https://avatars.githubusercontent.com/u/2183014?v=3","gravatar_id":"","url":"https://api.github.com/users/mclate","html_url":"https://github.com/mclate","followers_url":"https://api.github.com/users/mclate/followers","following_url":"https://api.github.com/users/mclate/following{/other_user}","gists_url":"https://api.github.com/users/mclate/gists{/gist_id}","starred_url":"https://api.github.com/users/mclate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mclate/subscriptions","organizations_url":"https://api.github.com/users/mclate/orgs","repos_url":"https://api.github.com/users/mclate/repos","events_url":"https://api.github.com/users/mclate/events{/privacy}","received_events_url":"https://api.github.com/users/mclate/received_events","type":"User","site_admin":false},"created_at":"2015-09-08T14:28:36Z","updated_at":"2015-09-08T14:28:36Z","body":"Can confirm it works in ansible `2.0.0`\r\n```\r\nansible 2.0.0 (devel 246e602fce) last updated 2015/09/08 14:21:26 (GMT +000)\r\n  lib/ansible/modules/core: (detached HEAD 34655e8e29) last updated 2015/09/08 14:21:38 (GMT +000)\r\n  lib/ansible/modules/extras: (detached HEAD 6a3cf63351) last updated 2015/09/08 14:21:48 (GMT +000)\r\n  config file =\r\n  configured module search path = None\r\n```\r\n`ansible-playbook playbook.yml -e var=val`:\r\n```\r\nTASK [my_role : Debug val] *****************************************************\r\nok: [localhost] => {\r\n    \"changed\": false,\r\n    \"{{ var }}\": \"val\"\r\n}\r\n```"}}