Files and Directories

  • file.copy
  • file.download
  • file.link
  • file.remove
  • directory.copy

Note

The following commands expect the from/source to point to files/directories which are themselves under a "files" directory. This is a restriction so that comtrya knows not to parse any .yaml file e.g. a config for a different tool as a manifest. To see how it works check the examples

  • file.link
  • file.copy
  • directory.copy

file.copy

Action used to copy a file from one location to another.

KeyTypeOptionalDescription
actionstringnofile.copy
fromstringnosource file
tostringnodestination file
templatebooleanyesrenders files using context providers
default: false
chmodintegeryesoctal permissions

Examples

# Simple file copy
- action: file.copy
  from: procs-config.toml
  to: "{{ user.config_dir }}/procs/config.toml"

# With template and permissions
- action: file.copy
  from: managed_file
  to: /root/file
  template: true
  chmod: 644
  
# With encrypted file
- action: file.copy
  from: encrypted-file
  to: /tmp/some-decrypted-file
  passphrase: "1KZ2EXDHSQKZFQP43JK2LPXUFZ8D365CM5WQXRSH97U7N9WKRVFKS0TCS30"

file.chown

This action will change the user and group owner of a file.

Note: In order to utilize this, must run comtrya as root. Also both a user and group need to be specified.

KeyTypeOptionalDescription
actionstringnofile.chown
pathstringnofile to change ownership on
userstringnouser to specify as file owner
groupstringnogroup to specify as file owner

Examples

actions:
  - action: file.chown
    path: ./files/some-file
    user: test
    group: test

file.download

This action will download a file.

KeyTypeOptionalDescription
actionstringnofile.download
fromstringnosource location
tostringnodestination file
owned_by_userstringyesuser for chown
owned_by_groupstringyesgroup for chown

An alias also exists such that source can be used in lieu of from and target can be used in lieu of to.

Example

actions:
  # This will be rendered with contexts
  - action: file.download
    from: https://google.com/robots.txt
    to: /tmp/google-robots.txt
    
  # This whill also run a chown step on downloaded file
  - action: file.download
    from: https://google.com/robots.txt
    to: /tmp/google-robots.txt
    owned_by_user: nobody
    owned_by_group: nobody

Note: utilizing chown functionality will require running comtrya as root. Also, both a user and a group need to be specified.

Create a symlink for files. This action can be used to symlink a single file or files in a directory.

KeyTypeOptionalDescription
actionstringnofile.link
fromstringnosymlink location
tostringnosymlink points to
walk dirbooleanyesWalk diles in directory
default: false
sourcestringyesUsed in conjunction with walk dir
in liue of from

Example

# Symlink for a single file
- action: file.link
  from: /root/symlink
  to: managed_file
  
# Symlink for all files in a directory
- action: file.link
  source: walker
  target: /tml/walker-123
  walk_dir: true

file.remove

Removes a file.

KeyTypeOptionalDescription
actionstringnofile.remove
targetstringnofile to be removed

Example

- action: file.remove
  target: /tmp/some-file-rendered

directory.copy

Copies a directory on the filesystem to another location.

KeyTypeOptionalDescription
actionstringnodirectory.copy
fromstringnosource directory
tostringnodestination directory

Example

- action: directory.copy
  from: managed_directory
  to: /root/location