How to copy files with ansible relatively to the role?

If you do not provide any path at all, just the filename, Ansible will pick it automatically from the files directory of the role.

- copy:
    src: foo.conf
    dest: /etc/foo.conf

Additionally, since Ansible 1.8, there is the variable role_path which you could use in your copy task.

- copy:
    src: "{{ role_path }}/files/foo.conf"
    dest: /etc/foo.conf

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)