Ansible Role files

This role manages file system entities such as files, directories and symlinks.

Runs on

  • RHEL 8 (and compatible)

Optional Requirements

  • It is recommeded to set inventory_ignore_patterns = '(host|group)_files' in your ansible.cfg on the Ansible Controller to ignore files in inventory_dir/host_files.

Tags

Tag

What it does

files

Manages files, directories and symlinks.

Optional Role Variables

Variable

Description

Default Value

files__directories__host_var /
files__directories__group_var

List of dictionaries containing the directories to manage. Subkeys:

  • path: Mandatory, string. Path to the directory.
  • state: Optional, string. State of the directory, one of present, absent. Defaults to present. Note: both operations are recursive.
  • mode: Optional, string. Mode (permissions) of the directory. Defaults to 0o755.
  • owner: Optional, string. Owner of the directory. Defaults to root.
  • group: Optional, string. Group of the directory. Defaults to root.

[]

files__files__host_var /
files__files__group_var

List of dictionaries containing the files to manage. Subkeys:

  • path: Mandatory, string. Path to the file.
  • content: Optional, string. Content of the file. If unset, the role copies the file from inventory_dir ~ "/host_files/" ~ inventory_hostname ~ "/" ~ item["path"].
  • state: Optional, string. State of the file, one of present, absent. Defaults to present.
  • mode: Optional, string. Mode (permissions) of the file. Defaults to 0o644.
  • owner: Optional, string. Owner of the file. Defaults to root.
  • group: Optional, string. Group of the file. Defaults to root.

[]

files__symlinks__host_var /
files__symlinks__group_var

List of dictionaries the symlinks to manage. Subkeys:

  • src: Mandatory, string. Path to source of the symlink.
  • dest: Mandatory, string. Path to dest of the symlink.
  • state: Optional, string. State of the symlink, one of present, absent. Defaults to present.

[]

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'
    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'
files__symlinks__host_var:
  - src: '/data/file1'
    dest: '/data/file1_link'

License

The Unlicense

Author Information

Linuxfabrik GmbH, Zurich