Ansible Role files
This role manages file system entities such as files, directories and symlinks.
Optional Requirements
It is recommeded to set
inventory_ignore_patterns = '(host|group)_files'
in youransible.cfg
on the Ansible Controller to ignore files ininventory_dir/host_files
.
Optional Role Variables
Variable |
Description |
Default Value |
---|---|---|
|
List of dictionaries containing the directories to manage. Subkeys:
|
|
|
List of dictionaries containing the files to manage. Subkeys:
|
|
|
List of dictionaries the symlinks to manage. Subkeys:
|
|
Example:
# optional
files__directories__host_var:
- path: '/data/a'
- path: '/data/b'
mode: 0o770
- path: '/data/b/c'
owner: 'apache'
files__files__host_var:
- path: '/data/file1'
# just use `|` so that there is a newline at the end of the file
content: |
echo "a script with
multiple lines"
mode: 0o755
- path: '/data/file2' # content will be taken from `inventory_dir/host_files/inventory_hostname/data/file3`
- path: '/data/file3'
state: 'absent'
- path: '/etc/hosts'
content: '{{ lookup("ansible.builtin.file", inventory_dir ~ "/group_files/all/etc/hosts") }}'
mode: 0o644
owner: 'root'
group: 'root'
files__symlinks__host_var:
- src: '/data/file1'
dest: '/data/file1_link'