command-output-to-file

Example:

# Create a file with a random number as content.
- command-output-to-file:
    command: od -A n -t d -N 1 /dev/urandom
    path: /tmp/random_nubmer
    remote_execute: true
    owner: freckles
    mode: '0700'

Description

Execute a command and write the output to a file.

By default, this executes a command on the local (controller) host, and writes the file to the remote one. This can be mixed-and-matched in any possible combination though.

This does not (yet) create either the user to execute the command as (execute_as) nor the owner of the result file (owner, group). Make sure to create those manually if necessary. It also does not create the parent directory of the target file.

Resources

Variables

Name Type Default Description

command

string --

The command to execute. Required

path

string --

The path to the output file. Required

chdir

string --

Change into this directory before running the shell command.

execute_as

string --

Needs to exist on the host that is used to execute.

group

string --

The group of the target file.

mode

string --

The mode of the target file.

owner

string --

The owner of the target file.

remote_execute

boolean False

Whether to execute the command on the remote host.

remote_write

boolean True

Whether to write the output file to the remote host, or locally.

stdin

string --

Set the stdin of the command directly to the specified value.

Examples

Example 1

Create a file with a random number as content.

Code
- command-output-to-file:
    command: od -A n -t d -N 1 /dev/urandom
    path: /tmp/random_nubmer
    remote_execute: true
    owner: freckles
    mode: '0700'
Description

Run a command that generates a random number, and write the result into the file /tmp/random_number. Ensure the file mode is '0700' and its user 'freckles'.

Command-line

frecklecute command-output-to-file --help

Usage: frecklecute command-output-to-file [OPTIONS]

  Execute a command and write the output to a file.

  By default, this executes a command on the local (controller) host, and
  writes the file to the remote one. This can be mixed-and-matched in any
  possible combination though.

  This does not (yet) create either the user to execute the command as
  (``execute_as``) nor the owner of the result file (``owner``, ``group``).
  Make sure to create those manually if necessary. It also does not create
  the parent directory of the target file.

Options:
  --command COMMAND               The command to execute.  [required]
  --path PATH                     The path to the output file.  [required]
  --chdir CHDIR                   Change into this directory before running
                                  the shell command.
  --execute-as EXECUTE_AS         The user to execute the command as.
  --group GROUP                   The group of the target file.
  --mode MODE                     The mode of the target file.
  --owner OWNER                   The owner of the target file.
  --remote-execute / --no-remote-execute
                                  Whether to execute the command on the remote
                                  host.
  --remote-write / --no-remote-write
                                  Whether to write the output file to the
                                  remote host, or locally.
  --stdin STDIN                   Set the stdin of the command directly to the
                                  specified value.
  --help                          Show this message and exit.