Tasks
Tasks in Mantis are the fundamental units of work within flows. They represent specific operations or actions to be performed as part of the infrastructure management process. Tasks are versatile and can be nested to create complex workflows or even contain entire flows.
Key Characteristics of Tasks
- Unit of Work: Each task represents a discrete operation in the infrastructure workflow.
- Nesting: Tasks can be nested, allowing for the creation of hierarchical structures of operations.
- Output Exports: Tasks can export their outputs, making the results available for use in subsequent tasks or flows.
- Specialized Integrations: Mantis provides specialized tasks for deep integrations with tools like Terraform and Kubernetes.
- Execution Focus: Tasks represent execution and scripts, distinguishing them from static configurations.
- Variable Injection: Tasks have the capability to inject variables into configurations, allowing for dynamic variable substitution that are needed in infrastructure as code flows.
Supported Task Types
Mantis supports a wide variety of task types, each designed for specific operations. Here's an overview of the supported task types:
Core Mantis Tasks:
mantis.core.TF
: Integrates with Terraform for infrastructure provisioning.mantis.core.K8s
: Manages Kubernetes resources and operations.mantis.core.Eval
: Performs local evaluations within Mantis.
Below tasks supported by Mantis are inherited from hofstadter. See hofstadter task types for more details.
API Interaction:
api.Call
: Executes API calls to external services.
Operating System and File System Tasks:
os.Exec
: Executes shell commands.os.FileLock
andos.FileUnlock
: Manages file locking operations.os.Getenv
: Retrieves environment variables.os.Glob
: Finds files matching a pattern.os.Mkdir
: Creates directories.os.ReadFile
: Reads file contents.os.ReadGlobs
: Reads multiple files matching a pattern.os.Sleep
: Pauses execution for a specified duration.os.Stdin
: Reads from standard input.os.Stdout
: Writes to standard output.os.Watch
: Monitors file system changes.os.WriteFile
: Writes content to a file.
Task Structure
A typical task in Mantis has the following structure:
task_name: {
@task(task_type)
// By default, tasks are executed in parallel. Use `dep` to control task ordering.
dep: [task_dependencies]
field1: {...}
field2: {...}
out: _ // field to export values for use in subsequent tasks.
}
@task(task_type)
: Specifies the type of task (e.g.,mantis.core.TF
,os.Exec
).dep
: Lists any tasks that must complete before this task runs.
Example: OpenTofu Task
Here's an example of a Terraform task that creates a DynamoDB table:
create_dynamodb_table: {
@task(mantis.core.TF)
dep: [setup_tf_providers]
config: resource: aws_dynamodb_table: hello_world_table: {
name: "HelloWorldTable"
billing_mode: "PAY_PER_REQUEST"
hash_key: "ID"
attribute: [{
name: "ID"
type: "S"
}]
tags: {
Name: "HelloWorldTable"
Environment: "Development"
}
}
exports: [{
jqpath: ".aws_dynamodb_table.hello_world_table.name"
var: "table_name"
}, {
jqpath: ".aws_dynamodb_table.hello_world_table.arn"
var: "table_arn"
}]
}
This task uses the mantis.core.TF
type to create a DynamoDB table and exports the table name and ARN for use in subsequent tasks.
By leveraging these various task types and their capabilities, Mantis enables the creation of sophisticated, multi-step workflows for managing complex infrastructure and application deployments.