file

This resource manages a file within the filesystem hierarchy of the client.

Relationship to other resources

The value of the path parameter must be unique among all file, directory and symlink resources.

A file implicitly depends on directory and symlink resources whose path parameters are ancestors to the file's path. For example when the path parameter of a file is set to /my/simple/path and there is a directory resource whose path is /my/simple, then the former implicitly depends on the latter.

Parameters

NameTypeDescriptionMandatoryDefault
ensurestringDetermines the desired state of the resource. One of present or absent.yespresent
pathstringPrimary parameter: An absolute filesystem path.yes
modestringThe file permission mode in octal notation.yes644
ownerstringThe name of the user who owns the file.yesroot
groupstringThe name of the group who owns the file.no
sourcestringAn absolute path to a file asset on the server. The remote file will be downloaded and its contents written to the file on the client. For example when this parameter is set to /my/example/file the file must exist on the server at $PULLCONF_ASSET_DIR/my/example/file in order to be downloaded successfully by the client. The downloaded file is not subject to variable substitution and will be written as-is. Ideal for binary or static text files. Mutually exclusive with content.no
contenthashSets the content that may optionally be substituted with server-side variables as well as client-side script output. Mutually exclusive with source.no

The content hash must contain the following keys:

NameTypeDescriptionMandatoryDefault
valuestringA single- or multiline string that contains the designated file content. Variables (${pullconf::<var>}) inside the string are substituted during validation, like in other resource parameters.yes
replacearrayAn array of commands that run on the client and replace placeholders inside value. Commands are run in order of definition.no

The replace array must contain hashes with the following keys:

NameTypeDescriptionMandatoryDefault
placeholderstringThe placeholder to be substituted by the command output.yes
commandarrayThe command and its arguments as strings. The program name and its arguments are each separate array items.yes
environmentarrayEnvironment variables that the process that executes the command should inherhit.no

The environment array must contain hashes with the following keys:

NameTypeDescriptionMandatoryDefault
namestringThe name of the environment variable.yes
valuestringThe value of the environment variable. If this parameter is omitted the variable will be set to an empty string.no

Note that command is not passed through a shell. One way to use shell-specific features such as pipes is to install a script (e.g. via file) first and then execute this script in command.

Examples

resources:
  - type: file
    parameters:
      path: /my/simple/example/file
resources:
  - type: file
    parameters:
      ensure: present
      path: /my/simple/example/file
	  owner: myuser
	  group: mygroup
	  source: /some/child/path/in/the/asset/directory
variables:
  sshd-port: 22
  sshd-allow-tcp-forwarding: yes

resources:
  - type: file
    parameters:
      ensure: present
      path: /etc/ssh/sshd_config
	  owner: root
	  group: root
	  content:
	    value: |
          Port ${pullconf::sshd-port}
		  Listen <ip>
		  
		  PermitRootLogin no
		  PasswordAuthentication no
		  PubkeyAuthentication yes
		  AllowTcpForwarding ${pullconf::sshd-allow-tcp-forwarding}
		replace:
		  - placeholder: <ip>
            command:
		      - /usr/local/sbin/determine-primary-ip-address.py