module

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 host
  • SHELLMIN_HOST_IP: IP address or hostname of the target host
  • SHELLMIN_HOST_USER: SSH username for the host
  • SHELLMIN_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 module
  • SHELLMIN_MODULE_ACTION: Action being performed (e.g., "install", "status")
  • SHELLMIN_MODULE_ARGS: Space-separated arguments passed to the module
  • SHELLMIN_MODULE_DIR: Directory containing the module scripts

Runtime Information

  • SHELLMIN_VERSION: Shellmin version
  • SHELLMIN_CONFIG_PATH: Path to the configuration file
  • SHELLMIN_STATE_DIR: Directory where state files are stored
  • SHELLMIN_OS: Detected OS of the target host
  • SHELLMIN_OS_VERSION: Detected OS version

Security & Execution

  • SHELLMIN_EXECUTION_ID: Unique ID for this execution
  • SHELLMIN_TIMEOUT: Execution timeout in seconds
  • SHELLMIN_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

env_string(env : Hash(String, String)) : Array(String)

Create environment string for execution

Converts the environment hash to a format suitable for Process execution

Source
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 details
  • module_name: Name of the module being executed
  • action: Action being performed
  • args: Array of arguments passed to the module
  • module_dir: Directory containing the module
  • execution_id: Unique identifier for this execution
  • remote_os: Detected OS of the target host
  • remote_os_version: Detected OS version
  • timeout: Execution timeout in seconds
  • verbose: Whether verbose output is enabled

Returns

Hash of environment variable names to values

Source
state_file_path(host_name : String, module_name : String) : String

Get the path to a state file for a specific host and module

Source
validate_env(env : Hash(String, String)) : Bool

Validate environment variables for security

Source