Skip to content

grlx.ingredients.file

The file ingredient handles all file operations on various file providers (such as local files, HTTP, etc.)

Deletes a file or directory

parametertyperequireddescription
namestringyesthe name/path of the file to delete
file.absent:
name: ~/.config/systemd/user/backup.service

Appends content to a file. Only appends the content if it doesn’t exist.

parametertyperequireddescription
namestringyesthe name/path of the file to append to
textstringnothe text to append to a file
makedirsboolnocreate parent directories if they do not exist
sourcestringnoappend lines from a file sourced from this path/URL
source_hashstringnohash to verify the file specified by source
template experimentalboolnotreat this file as a template and render it before placing
sourcesstring/listnoappends all content specified in list, checked in order
source_hashesstring/listnocorresponding hashes for sources
file.append:
- name: /etc/profile
- text: |
export PATH=$PATH:/usr/local/go/bin

Validates if a file is cached in the sprout’s cache. If it isn’t the file will be cached.

parametertyperequireddescription
namestringyesthe path describing where to save the cached file
sourcestringyesa file source (such as HTTP, file, etc.) to reference
hashstringconditional (required if skip_verify is false)a valid hash of the source file
skip_verifybooleannowhether to skip hash validation, false by default
file.cached:
- name: /tmp/cachedfile
- source: https://go.dev/dl/go1.21.3.src.tar.gz
- hash: sha256=186f2b6f8c8b704e696821b09ab2041a5c1ee13dcbc3156a13adcf75931ee488

Checks if a file contains a given selection. If multiple sources are provided, all must be satisfied.

parametertyperequireddescription
namestringyesthe name/path of the file to check
textstringnothe item to search for
sourcestringnoa file source (such as HTTP, file, etc.) to reference
source_hashstringconditional (required if source provided)a hash for a given source
sourceslistnoa list of sources to check against
source_hasheslistconditional (required if skip_verify is false)a list of source hashes
skip_verifybooleannowhether to skip hash validation, false by default
template experimentalboolnotreat this file as a template and render it before placing it

Copies content into a given file

parametertyperequireddescription
namestringyesRepresents the name of a file or directory
makedirsboolno (default: false)Determines whether directories should be created if they don’t exist
sourcestringnoRepresents a source file’s path or name
source_hashstringconditional (required if source is provided and skip_verify is false)Represents the hash of a source file, used for verification
textstring/listnoRepresents the content of a file. Can be a single string or a list of items
sourceslistnoRepresents multiple source files
template experimentalboolnotreat this file as a template and render it before placing it
skip_verifybooleannowhether to skip hash validation, false by default
source_hasheslistconditional (required if sources is provided and skip_verify is false)Represents the hashes for the multiple source files mentioned in sources
file.content:
- name: /srv/nginx/nginx.conf
- makdirs: true
- text: |
server {
listen 8080;
root /data/up1;
location / {
}
}

Handles many directory operations. Ensures that a directory exists with the given permissions.

parametertyperequireddescription
namestringyesthe name/path of the directory
makedirsboolnooption to make directory if it doesn’t exist, defaults to true
userstringnothe user who will own the directory
groupstringnothe group who will own the directory
dir_modestringnothe directory mode
file_modestringnothe file mode to set
recurseboolnowhether to recurse the directories and apply permissions
file.directory:
- name: /tmp/item
- makdirs: false
- user: grlx
- group: grlx
- dir_mode: 755
- recurse: false

Checks if a file exists.

parametertyperequireddescription
namestringyesthe name/path of the file
file.exists:
- name: /tmp/exists

Manage many properties of a file concurrently, safely

parametertyperequireddescription
namestringyesRepresents the name of a file or directory
sourcestringnoRepresents a source file’s path or name
source_hashstringconditional (required if skip_verify is false)Represents the hash of a source file, used for verification
userstringnothe user who will own the directory
groupstringnothe group who will own the directory
modestringnothe file’s mode
template experimentalboolnotreat this file as a template and render it before placing it
makedirsboolno (default: false)Determines whether directories should be created if they don’t exist
dir_modestringnothe directory mode
textstring/listnoRepresents the content of a file. Can be a single string or a list of items
sourceslistnoRepresents multiple source files
skip_verifybooleannowhether to skip hash validation, false by default
source_hasheslistconditional (required if sources is provided)Represents the hashes for the multiple source files mentioned in sources
file.managed:
- name: /srv/nginx/nginx.conf
- makdirs: true
- user: pi
- group: wheel
- text: |
server {
listen 8080;
root /data/up1;
location / {
}
}

Checks if a file is missing.

parametertyperequireddescription
namestringyesthe name/path of the file
file.missing:
- name: /tmp/missing

Prepends content to a file. Only prepends the content if it doesn’t exist.

parametertyperequireddescription
namestringyesthe name/path of the file to prepend to
textstringnothe text to prepend to a file
makedirsboolnocreate parent directories if they do not exist
sourcestringnoprepend lines from a file sourced from this path/URL
source_hashstringconditional (required if source is provided and skip_verify is false)hash to verify the file specified by source
skip_verifybooleannowhether to skip hash validation, false by default
template experimentalboolnotreat this file as a template and render it before placing it
sourcesstring/listnolist source, but in list format
source_hashesstring/listnocorresponding hashes for sources
file.prepend:
- name: /etc/profile
- text: |
export PATH=$PATH:/usr/local/go/bin

Creates a symlink at name that points to target

parametertyperequireddescription
namestringyesthe name/path of the file
targetstringyesthe target path to link to
makedirsstringnomake parent directories if missing
userstringnothe user who should own the symlink
groupstringnothe group who should own the symlink
modestringnothe desired filemode of the symlink
file.symlink:
- name: ~/localbash
- target: /usr/bin/bash
- user: pi
- group: wheel
- mode: "655"

Performs a touch on a file

parametertyperequireddescription
namestringyesthe name/path of the file
atimetime (RFC339)nothe access time to set the file to, set to the current time by default
mtimetime (RFC339)nothe modified time to set the file to, sets to the current time by default
makedirsboolyeswhether or not to create any provided parent directories, false by default
file.touch:
- name: /tmp/parent/new-file
- atime: Mon, 06 Nov 2023 00:00:00 +0000
- mtime: Mon, 06 Nov 2023 00:00:00 +0000
- makedirs: true