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

20 views
Skip to first unread message

Marc Abramowitz

unread,
Sep 18, 2014, 11:48:33 PM9/18/14
to ansible...@googlegroups.com
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

Marc Abramowitz

unread,
Sep 18, 2014, 11:52:27 PM9/18/14
to ansible...@googlegroups.com
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...?
Reply all
Reply to author
Forward
0 new messages