Bootstrap FreeKB - Ansible - Role Files
Ansible - Role Files

Updated:   |  Ansible articles

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

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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