Way for a role to refer to files relative to the role?

So roles have a “files” directory and for some actions and attributes they are evaluated relative to this directory (e.g.: the “src” attribute of the “copy” module). So with:

roles/common/tasks/main.yml

  • name: Copy in ssh key files
    copy:
    src=“devops.pem”
    dest=“/home/{{ ansible_user_id }}/.ssh/id_rsa”
    mode=600
    tags:
  • ssh_key

src=“devops.pem” will find my file in roles/common/files/devops.pem

For other actions, this doesn’t work – for example:

  • name: Make sure that devops.pem is not group/world readable
    local_action: file path=devops.pem mode=600
    tags:
  • ssh_key
  • ssh_key_local

In this case, it will not find the file in roles/common/files/devops.pem – it seems to look for the file relative to the playbook?

How can I reference a file relative to the role I’m referencing it in? – e.g.: something like:

  • name: Make sure that devops.pem is not group/world readable
    local_action: file path={{ current_role_dir }}/files/devops.pem mode=600
    tags:
  • ssh_key
  • ssh_key_local

local_action: file path={{ inventory_dir }}/…/roles/common/files/devops.pem mode=600

works, but hopefully there’s a cleaner way that doesn’t have to include “…/roles/common” in it…?