How can I get the current role name in an ansible task yaml file?
I would like to do something like this
---
# role/some-role-name/tasks/main.yml
- name
As of Ansible 2.2:
{{role_name}}
As of Ansible 2.1:
{{role_path|basename}}
Older versions:
There is no way to do this in the current version of Ansible, here are a couple options that might work for you instead:
1) Use set_fact to set a role_name var to the name the of role as the first task in your tasks/main.yml file
- set_fact: role_name=some-role-name
2) Pass a parameter to your role that has the name
- roles:
- role: some-role-name
role_name: some-role-name