komando_parallel_tasks
The komando_parallel_hosts
function is a function to execute multiple task on a host in parallel. 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.
tasks
: a table that contains the tasks to be executed on the target host. Each task is represented by 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 tasks = {
{
name = "install neovim package",
komandan.modules.apt({
package = "neovim",
update_cache = true
}),
elevate = true,
},
{
name = "mkdir",
komandan.modules.cmd({
cmd = "mkdir /tmp/new_dir"
})
},
{
name = "ls",
komandan.modules.cmd({
cmd = "ls -hal"
})
}
}
komandan.komando_parallel_tasks(host, tasks)
This function will execute the module on the target server and return a table with the following 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.