Shellmin::Environment
Environment Variable System for Script Context
This module provides comprehensive environment variables that scripts can use to access host information, module context, configuration, and state.
Environment Variables Provided
Host Information
SHELLMIN_HOST_NAME: Name/alias of the target hostSHELLMIN_HOST_IP: IP address or hostname of the target hostSHELLMIN_HOST_USER: SSH username for the hostSHELLMIN_HOST_KEY_PATH: Path to SSH key (if used)SHELLMIN_HOST_PORT: SSH port (default: 22)
Module Information
SHELLMIN_MODULE_NAME: Name of the executing moduleSHELLMIN_MODULE_ACTION: Action being performed (e.g., "install", "status")SHELLMIN_MODULE_ARGS: Space-separated arguments passed to the moduleSHELLMIN_MODULE_DIR: Directory containing the module scripts
Runtime Information
SHELLMIN_VERSION: Shellmin versionSHELLMIN_CONFIG_PATH: Path to the configuration fileSHELLMIN_STATE_DIR: Directory where state files are storedSHELLMIN_OS: Detected OS of the target hostSHELLMIN_OS_VERSION: Detected OS version
Security & Execution
SHELLMIN_EXECUTION_ID: Unique ID for this executionSHELLMIN_TIMEOUT: Execution timeout in secondsSHELLMIN_VERBOSE: Whether verbose output is enabled
Usage in Scripts
#!/usr/bin/bash
echo "Installing on $SHELLMIN_HOST_NAME ($SHELLMIN_HOST_IP)"
echo "Module: $SHELLMIN_MODULE_NAME, Action: $SHELLMIN_MODULE_ACTION"
if [ "$SHELLMIN_OS" = "ubuntu" ]; then
apt-get update
else
yum update
fi
Instance methods
Create environment string for execution
Converts the environment hash to a format suitable for Process execution
generate_script_env(host_info : NamedTuple(name: String, host: String, user: String, port: Int32, key_path: String | Nil, password: String | Nil), module_name : String, sub_modules : Array(String), action : String, args : Array(String), module_dir : String, execution_id : String, system_info : Hash(String, String), timeout : Int32 = 300, verbose : Bool = false, env_overrides : Hash(String, String) = Hash(String, String).new) : Hash(String, String)
Generate environment variables for script execution
Arguments
host_info: NamedTuple with host connection detailsmodule_name: Name of the module being executedaction: Action being performedargs: Array of arguments passed to the modulemodule_dir: Directory containing the moduleexecution_id: Unique identifier for this executionremote_os: Detected OS of the target hostremote_os_version: Detected OS versiontimeout: Execution timeout in secondsverbose: Whether verbose output is enabled
Returns
Hash of environment variable names to values
Get the path to a state file for a specific host and module