Task Operations Usage¶
Tasks are the atomic units of work in DRP. Each task defines one or more templates (scripts or configuration files) that are rendered and executed on a machine during provisioning. Use drpcli tasks to manage the task library.
List Tasks¶
# List all defined tasks
drpcli tasks list
# List tasks and show only names
drpcli tasks list | jq -r '.[].Name' | sort
# Search for tasks by name pattern
drpcli tasks list | jq -r '[.[] | select(.Name | contains("ntp"))] | .[].Name'
Get Task Details¶
# Show a specific task by name
drpcli tasks show my-configure-ntp
# Show the required parameters for a task
drpcli tasks show my-configure-ntp | jq '{RequiredParams:.RequiredParams,OptionalParams:.OptionalParams}'
# Show template names within a task
drpcli tasks show my-configure-ntp | jq '[.Templates[].Name]'
Create a Task¶
Tasks can be created from JSON or YAML. The most important fields are Name, Templates, RequiredParams, and OptionalParams.
# Create a simple inline task
drpcli tasks create '{
"Name": "hello-world",
"Description": "Print hello world",
"Templates": [
{
"Name": "hello.sh",
"Path": "/tmp/hello.sh",
"Contents": "#!/bin/bash\necho \"Hello from {{ .Machine.Name }}\"\n"
}
]
}'
# Create a task from a YAML file
drpcli tasks create - < my-task.yaml
A task YAML with declared parameters:
Name: configure-ntp
Description: "Configure NTP servers on the target machine"
RequiredParams:
- ntp/servers
OptionalParams:
- ntp/pool-name
Templates:
- Name: configure-ntp.sh
Path: /tmp/configure-ntp.sh
Contents: |
#!/bin/bash
set -e
{{ range (.Param "ntp/servers") -}}
echo "server {{ . }} iburst" >> /etc/chrony.conf
{{ end -}}
systemctl restart chronyd
Update a Task¶
# Update a task's description
drpcli tasks update my-configure-ntp '{"Description":"Configure NTP servers using chrony"}'
# Add a required parameter to an existing task
drpcli tasks update my-configure-ntp '{"RequiredParams":["ntp/servers","ntp/pool-name"]}'
# Replace a task's template contents (full update)
drpcli tasks update my-configure-ntp - < updated-task.yaml
Destroy a Task¶
# Remove a task (fails if the task is referenced by a stage)
drpcli tasks destroy my-configure-ntp
Before destroying, check which stages reference the task:
Inspect Field Information¶
Using Tasks in Stages¶
Once a task is created, reference it by name in a stage's Tasks list: