Komandan has several built-in modules that can be used to perform various tasks on the target server.
This is the multi-page printable view of this section. Click here to print.
Modules
- 1: cmd
- 2: script
- 3: upload
- 4: download
- 5: apt
- 6: lineinfile
- 7: template
- 8: systemd_service
- 9: postgresql_user
1 - cmd
The cmd module allows you to execute a shell command on the target server.
Arguments
cmd: a string that contains the shell command to be executed.
Usage Example
local task = {
name = "Execute a command",
komandan.modules.cmd({
cmd = "ls -l"
})
}
komandan.komando(host, task)
2 - script
The script module allows you to execute a script on the target server.
Arguments
script: a string that contains the script to be executed.from_file: a string that contains the local path to the script file to be executed on the target server. (scriptandfrom_fileparameters are mutually exclusive)interpreter: a string that specifies the interpreter to use for the script. If not specified, the script will be executed using the default shell.
Usage Example
local task = {
name = "Execute a script",
komandan.modules.script({
script = "print('Hello from script')",
interpreter = "python"
})
}
komandan.komando(host, task)
3 - upload
The upload module allows you to upload a file to the target server.
Arguments
src: a string that contains the path to the file to be uploaded.dst: a string that contains the path to the destination file on the target server.
Usage Example
local task = {
name = "Upload a file",
komandan.modules.upload({
src = "/path/to/local/file",
dst = "/path/to/remote/file"
})
}
komandan.komando(host, task)
4 - download
The download module allows you to download a file from the target server.
Arguments
src: a string that contains the path to the file to be downloaded.dst: a string that contains the path to the destination file on the local machine.
Usage Example
local task = {
name = "Download a file",
komandan.modules.download({
src = "/path/to/remote/file",
dst = "/path/to/local/file"
})
}
komandan.komando(host, task)
5 - apt
The apt module allows you to install an APT package on the target server.
Arguments
package: a string that contains the name of the package to be installed.action: a string that specifies the action to be taken on the package. (default isinstall. Supported actions:install,remove,purge,upgrade,autoremove)update_cache: a boolean that indicates whether to update the package cache before installing the package. (default isfalse)install_recommends: a boolean that indicates whether to install recommended packages. (default istrue)
Usage Example
local task = {
name = "Install apache2",
komandan.modules.apt({
package = "apache2",
update_cache = true
})
}
komandan.komando(host, task)
6 - lineinfile
The lineinfile module allows you to modify a file by adding or removing lines.
Arguments
path: a string that contains the path to the file to be modified.line: a string that contains the line to be added or removed.state: a string that contains the state of the line. Can be “present” or “absent”. (default is “present”)pattern: a string that contains the pattern (regular expression) to search for in the file. (optional)insert_after: a string that contains the line to insert the new line after. (optional)insert_before: a string that contains the line to insert the new line before. (optional)create: a boolean that indicates whether to create the file if it does not exist. (default isfalse)backup: a boolean that indicates whether to create a backup of the file before modifying it. (default isfalse)
Usage Example
local task = {
name = "Add a line in a file",
komandan.modules.lineinfile({
path = "/tmp/target_file.txt",
line = "This is a new line",
state = "present",
create = true,
backup = true,
}),
}
7 - template
The template module allows you to create a file using a jinja template.
Arguments
src: a string that contains the path to the template file on the local machine.dst: a string that contains the path to the destination file on the target server.vars: a table that contains the variables to be used in the template.
Usage Example
local task = {
name = "Create a file using a template",
komandan.modules.template({
src = "/path/to/template.jinja",
dst = "/tmp/target_file.txt",
vars = {
name = "John Doe",
age = 30,
},
}),
}
8 - systemd_service
The systemd_service module allows you to manage a systemd service on a target server.
Arguments
name: a string that contains the name of the service to be managed.action: a string that specifies the action to be taken on the service. (default isstart. Supported actions:start,stop,restart,reload,enable,disable)daemon_reload: a boolean that indicates whether to reload the systemd daemon before taking the action. (default isfalse)force: a boolean that indicates whether to force the action to be taken. (default isfalse)
Usage Example
local task = {
name = "Restart apache2 service",
komandan.modules.systemd_service({
name = "apache2.service",
action = "restart",
})
}
komandan.komando(host, task)
9 - postgresql_user
The postgresql_user module allows you to create a user in a PostgreSQL server.
Arguments
name: a string that contains the name of the user to be created.password: a string that contains the password for the user.role_attr_flags: a string that contains the role attribute flags for the user.action: a string that specifies the action to be taken on the user. (default iscreate. Supported actions:create,drop)
Usage Example
local task = {
name = "Create a user in PostgreSQL",
komandan.modules.postgresql_user({
name = "myuser",
password = "mysecretpassword",
role_attr_flags = "REPLICATION",
})
}
komandan.komando(host, task)