Commands module
This module implements command execution on Linux systems.
Usage
The module takes the following arguments:
Name | Description | Possible values | Required |
---|---|---|---|
command | Command to be executed | A path on the filesystem or a complete command (if in_shell is set to true, args is ignored ) | Yes |
args | Arguments to the command | Array of strings in JSON format (e.g., ["-u", "bob"]). If in_shell is set to true , args is ignored | No |
run_in_audit_mode | Controls the running mode of the command | true /false (default: false ) | No |
in_shell | Controls if the command is executed inside a shell | true /false (default: false ) | No |
shell_path | Shell path (used only in shell mode) | A path to a shell binary (default: /bin/sh ) | No |
chdir | Directory from where to execute the command | A path to a directory | No |
timeout | Timeout for command execution | A timeout in seconds (default: 30 ) | No |
stdin | Input passed to the stdin of the executed command | A string | No |
stdin_add_newline | Controls the appending of a newline to the stdin input | true /false (default: true ) | No |
compliant_codes | Compliant codes | Compliant codes (example: "" , 0 , 1 ) | No |
repaired_codes | Repaired codes | Repaired codes (example: 0 , 1 ) | No |
output_to_file | File to store the output of the command | A valid file path | No |
strip_output | Controls the strip of the content inside the output file | true /false (default: true ) | No |
uid | UID used by the executed command | A valid UID (example: 0 ) | No |
user | User used to run the command (mutually exclusive with the uid argument) | A valid username (example: root ) | No |
gid | GID used by the executed command | A valid GID (example: 0 ) | No |
group | Group used to run the command | A valid group name (mutually exclusive with the gid argument) | No |
umask | Umask used by the executed command | A valid umask (example: 0022 ) | No |
env_vars | Environment variables used by the executed command | Dictionary of string key-value pairs in JSON format (e.g., {"LANG": "en_US.UTF-8"}). | No |
show_content | Controls output in the report | true /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