aap

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2026 License: Apache-2.0 Imports: 11 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package aap provides a client for interacting with the Ansible Automation Platform (AAP) REST API.

Index

Constants

View Source
const (
	// APIVersion is the AAP API version path
	APIVersion = "v2"

	// AAP template endpoint paths
	JobTemplatesEndpoint         = "job_templates"
	WorkflowJobTemplatesEndpoint = "workflow_job_templates"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CanCancelJobResponse

type CanCancelJobResponse struct {
	CanCancel bool `json:"can_cancel"`
}

CanCancelJobResponse contains the response from checking if a job can be canceled.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides an HTTP client for interacting with AAP (Ansible Automation Platform) REST API.

func NewClient

func NewClient(baseURL, token string, insecureSkipVerify bool) *Client

NewClient creates a new AAP API client. When insecureSkipVerify is true, TLS certificate verification is disabled (InsecureSkipVerify) for AAP API requests.

func (*Client) CanCancelJob

func (c *Client) CanCancelJob(ctx context.Context, jobID string) (bool, error)

CanCancelJob checks if a job can be canceled. Returns true if the job is in a state that allows cancellation (pending/running).

func (*Client) CancelJob

func (c *Client) CancelJob(ctx context.Context, jobID string) error

CancelJob cancels a pending or running job. Returns nil if successful (HTTP 202), or an error if the job cannot be canceled (HTTP 405). Note: When canceling a job, AAP issues a SIGINT to the ansible-playbook process, which causes Ansible to stop dispatching new tasks. Tasks already dispatched to remote hosts will run to completion.

func (*Client) ClearTemplateCache

func (c *Client) ClearTemplateCache()

ClearTemplateCache removes all templates from the cache.

func (*Client) GetJob

func (c *Client) GetJob(ctx context.Context, jobID string) (*Job, error)

GetJob retrieves job status by job ID.

func (*Client) GetTemplate

func (c *Client) GetTemplate(ctx context.Context, templateName string) (*Template, error)

GetTemplate retrieves a template by name with caching. Checks cache first, then queries AAP if not cached. Returns the template with ID, name, and type.

func (*Client) GetTemplateByName

func (c *Client) GetTemplateByName(ctx context.Context, templateName string) (*Template, error)

GetTemplateByName queries AAP to find a template by name. Returns the template with its ID, name, and type. This method does not use caching.

func (*Client) LaunchJobTemplate

LaunchJobTemplate launches a job template and returns the job ID.

func (*Client) LaunchWorkflowTemplate

LaunchWorkflowTemplate launches a workflow template and returns the job ID.

type Job

type Job struct {
	ID              int       `json:"id"`
	Status          string    `json:"status"`
	Started         time.Time `json:"started"`
	Finished        time.Time `json:"finished"`
	ExtraVars       string    `json:"extra_vars"` // AAP returns this as a JSON-encoded string
	ResultTraceback string    `json:"result_traceback"`
}

Job represents an AAP job with status information.

type LaunchJobTemplateRequest

type LaunchJobTemplateRequest struct {
	TemplateName string
	ExtraVars    map[string]any
}

LaunchJobTemplateRequest contains parameters for launching a job template.

type LaunchJobTemplateResponse

type LaunchJobTemplateResponse struct {
	JobID int `json:"id"`
}

LaunchJobTemplateResponse contains the response from launching a job template.

type LaunchWorkflowTemplateRequest

type LaunchWorkflowTemplateRequest struct {
	TemplateName string
	ExtraVars    map[string]any
}

LaunchWorkflowTemplateRequest contains parameters for launching a workflow template.

type LaunchWorkflowTemplateResponse

type LaunchWorkflowTemplateResponse struct {
	JobID int `json:"id"`
}

LaunchWorkflowTemplateResponse contains the response from launching a workflow template.

type MethodNotAllowedError

type MethodNotAllowedError struct {
	Operation string // e.g., "cancel job 123"
	URL       string
}

MethodNotAllowedError indicates the requested operation is not allowed (HTTP 405). For job cancellation, this typically means the job is already in a terminal state.

func (*MethodNotAllowedError) Error

func (e *MethodNotAllowedError) Error() string

type NotFoundError

type NotFoundError struct {
	Resource string // e.g., "job 123", "template foo"
	URL      string
}

NotFoundError indicates a resource was not found in AAP (HTTP 404). This typically happens when querying for jobs that have been purged.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Template

type Template struct {
	ID   int          `json:"id"`
	Name string       `json:"name"`
	Type TemplateType `json:"-"` // Type is determined by which endpoint returned the template
}

Template represents an AAP job template or workflow job template.

type TemplateType

type TemplateType string

TemplateType represents the type of AAP template.

const (
	TemplateTypeJob      TemplateType = "job_template"
	TemplateTypeWorkflow TemplateType = "workflow_job_template"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL