role name as variable

I’m sure this is dead simple, but googling seems hard since most posts contain the words “role” and “variable”!

I have versioned playbooks. I would like to stick a file somewhere on the target system that explains what role was used, a time stamp, and a version. I use maven as it happens. I thought I could something like this:

roles/install_iod_base/tasks/pom.yml

  • name: copy the pom for this trunk/branch/tag

copy: src=…/…/…/…/pom.xml dest=~/pom.xml-{{ ansible_date_time.date }}-{{ ansible_date_time.time }} mode=0644

I would like to include this snippet in all my roles, and therefore it would be useful to have something like

copy: src=…/…/…/…/pom.xml dest=~/pom.xml-{{ ansible_role }}-{{ ansible_date_time.date }}-{{ ansible_date_time.time }} mode=0644

How can I enumerate the current roles name?

Generally speaking, a role shouldn’t change behavior based on it’s name, and this would become confusing if role dependencies were used (should the dependent role set thename, etc)

So basically you can’t do this, but you could do a

  • set_fact: role_name=“xxx” if you wanted or something like that.