Remote execution

Execute Bash functions remote

A bash function can be executed on a remote host simply by executing:

execute_function_over_ssh --hostname "my-server" --function_name run_me_on_my_server --example_arg1 "hello from remote";

The following functions are available while executing a function remote:

confirm_or_abort
log_trace
log_debug
log_info
log_info_no_cr
log_warn
log_error
log_fatal
log_text
check_required_argument
check_required_arguments
check_required_variable
check_required_variables
check_required_file
import_args
replace_spaces
function_exists
update_line_in_file
remove_lines_in_file_that_start_with
block_in_file
file_contains_pattern

And the following variables:

ON_PROVISIONING_SERVER  - always "false" when executing remote
APPLICATION_USER        - username of the user that's executing this function
INTERACTIVE             - "true" if the action was started from the UI, otherwise "false"

To add other functions to the list, add them as dependencies through creating an environment variabele called `"function__function_dependencies”. See below for an example.


function echo_something() {
    log_info "In function 'echo_something' on the remote server.";
}

function echo_something2() {
    log_debug "In function 'echo_something2' on the remote server.";
}

function_run_me_on_my_server_function_dependencies="echo_something echo_something2";

function run_me_on_my_server() {
  local function_name="run_me_on_my_server" example_arg1;
  import_args "$@";
  check_required_arguments "$function_name" example_arg1
  log_info "Example arg1: $example_arg1.";
  echo_something
  echo_something2
}