Create a Custom Module

To create a custom module, you can create a function that returns a komandan.KomandanModule object. The argument should contain the name field of the module.

The main function of the module is the run function. This function should contain the code that will be executed. To send a command or another action to the target server, you can use the helper functions provided by Komando. (see Module Helper Functions)

To create a cleanup function, you can use the cleanup function. This function will be executed after the run function.

Example of a Custom Module

function my_module(params)
  let module = komandan.KomandanModule:new({ name = "My Module", params = params })

  module.run = function(self)
    self.ssh:cmd("mkdir /tmp/" .. self.params.dirname)
  end

  module.cleanup = function(self)
    -- Cleanup code
  end

  return module
end

In the example above, the my_module function returns a komandan.KomandanModule object. The name field of the module is set to “My Module”. The run function of the module creates a directory on the target server with name from the dirname argument.

Usage Example of a Custom Module

local host = {
  address = "10.20.30.41",
  user = "user1",
}

local task = {
  name = "Run custom module",
  my_module({
    dirname = "test"
  })
}

komandan.komando(host, task)