komando
The komando
function is a function to execute a task on a host. It takes two arguments:
host
: a table that contains the following fields:address
: the IP address or hostname of the target server.port
: the SSH port to use for the connection (default is 22).user
: the username to connect to the server.private_key_file
: the path to the private key file for authentication.private_key_pass
: the passphrase for the private key file (optional).password
: the password to use for authentication if no private key is provided.
task
: a table that contains the following fields:name
: a string that describes the task. It is used for logging purposes. (optional)- module: a table that contains the module to be executed and its arguments. This field is defined without a key.
elevate
: a boolean that indicates whether to run the task with elevated privileges. (default isfalse
)as_user
: a string that contains the username to run the task as. (optional)ignore_exit_code
: a boolean that indicates whether to ignore the exit code of the task. Iftrue
, the script will continue even if the task returns a non-zero exit code. (default isfalse
)env
: a table that contains environment variables to be set for the task. (optional)
Usage Example
local host = {
address = "10.20.30.41",
user = "user1",
private_key_file = "/path/to/private/key",
}
local task = {
name = "install neovim package",
komandan.modules.apt({
package = "neovim",
update_cache = true
}),
elevate = true,
}
komandan.komando(host, task)
This function will execute the module on the target server and return the results:
stdout
: a string that contains the standard output of the module.stderr
: a string that contains the standard error output of the module.exit_code
: an integer that contains the exit code of the module.