Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Commands module

This module implements command execution on Linux systems.

Usage

The module takes the following arguments:

NameDescriptionPossible valuesRequired
commandCommand to be executedA path on the filesystem or a complete command (if in_shell is set to true, args is ignored)Yes
argsArguments to the commandArray of strings in JSON format (e.g., ["-u", "bob"]). If in_shell is set to true, args is ignoredNo
run_in_audit_modeControls the running mode of the commandtrue/false (default: false)No
in_shellControls if the command is executed inside a shelltrue/false (default: false)No
shell_pathShell path (used only in shell mode)A path to a shell binary (default: /bin/sh)No
chdirDirectory from where to execute the commandA path to a directoryNo
timeoutTimeout for command executionA timeout in seconds (default: 30)No
stdinInput passed to the stdin of the executed commandA stringNo
stdin_add_newlineControls the appending of a newline to the stdin inputtrue/false (default: true)No
compliant_codesCompliant codesCompliant codes (example: "", 0, 1)No
repaired_codesRepaired codesRepaired codes (example: 0, 1)No
output_to_fileFile to store the output of the commandA valid file pathNo
strip_outputControls the strip of the content inside the output filetrue/false (default: true)No
uidUID used by the executed commandA valid UID (example: 0)No
userUser used to run the command (mutually exclusive with the uid argument)A valid username (example: root)No
gidGID used by the executed commandA valid GID (example: 0)No
groupGroup used to run the commandA valid group name (mutually exclusive with the gid argument)No
umaskUmask used by the executed commandA valid umask (example: 0022)No
env_varsEnvironment variables used by the executed commandDictionary of string key-value pairs in JSON format (e.g., {"LANG": "en_US.UTF-8"}).No
show_contentControls output in the reporttrue/false (default: true)No

CLI

The module provides a CLI to help debug the execution and audit of commands.

$ /opt/rudder/bin/rudder-module-commands --help
Usage: rudder-module-commands [OPTIONS] <COMMAND> [ARGS]...

Arguments:
  <COMMAND>  Command to be executed
  [ARGS]...  Arguments to the command

Options:
  -a, --audit
          Enable audit mode
  -d, --dry-run
          Simulate the command execution without making any changes
      --in-shell
          Specify whether the command should be executed within a shell
      --shell-path <SHELL_PATH>
          Define the path to the shell to be used (applicable only in shell mode)
      --chdir <CHDIR>
          Set the working directory from which the command will be executed
      --timeout <TIMEOUT>
          Define a timeout duration for the command execution
      --stdin <STDIN>
          Provide input to the standard input (stdin) of the executed command
      --stdin-no-newline
          Control whether a newline character is appended to the stdin input
      --output-to-file <OUTPUT_TO_FILE>
          Define a file path to store the output generated by the command
      --strip-output
          Controls if the EOL is strip from the output
      --uid <UID>
          Specify the user ID (UID) under which the command will be executed
      --user <USER>
          Specify the user under which the command will be executed
      --gid <GID>
          Specify the group ID (GID) under which the command will be executed
      --group <GROUP>
          Specify the group under which the command will be executed
      --umask <UMASK>
          Set the umask value for the executed command
      --share-env
          Control whether to share the environment variables with the executed command
  -h, --help
          Print help
  -V, --version
          Print version