FreeKB - Ansible Role Files
Ansible - Role Files

Role Files are similar to Role Templates and the copy module. Each are used to copy a file from the control node (that's your Ansible server) to managed nodes (e.g. target system). The big difference between is that template files can contain jinja2 references, role files cannot.

Role Files are part of roles. Role Files are placed in the role files directory. For example, let's say you've the following files in the role files directory.

/etc/ansible/roles/fooRole/files/foo.txt

 

Since role files are part of a role, lets say you have a master playbook that invokes fooRole, like this.

---
- hosts: all
  roles:
    - role: fooRole

 

And let's say /etc/ansible/roles/fooRole/tasks/main.yml contains the following. Running this play will copy foo.txt on the control node to /tmp/foo.txt on the managed node.

- name: copy foo.txt to /tmp/foo.txt
  files:
    src: foo.txt
    dest: /tmp/foo.txt

 

While not required, I try to always include the relative directory to the file, as this prevent issues when some other role includes fooRole.

- name: copy foo.txt to /tmp/foo.txt
  files:
    src: roles/fooRole/files/foo.txt
    dest: /tmp/foo.txt

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 120b3 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |