Documentation
¶
Overview ¶
Package aap provides a client for interacting with the Ansible Automation Platform (AAP) REST API.
Index ¶
- Constants
- type CanCancelJobResponse
- type Client
- func (c *Client) CanCancelJob(ctx context.Context, jobID string) (bool, error)
- func (c *Client) CancelJob(ctx context.Context, jobID string) error
- func (c *Client) ClearTemplateCache()
- func (c *Client) GetJob(ctx context.Context, jobID string) (*Job, error)
- func (c *Client) GetTemplate(ctx context.Context, templateName string) (*Template, error)
- func (c *Client) GetTemplateByName(ctx context.Context, templateName string) (*Template, error)
- func (c *Client) LaunchJobTemplate(ctx context.Context, req LaunchJobTemplateRequest) (*LaunchJobTemplateResponse, error)
- func (c *Client) LaunchWorkflowTemplate(ctx context.Context, req LaunchWorkflowTemplateRequest) (*LaunchWorkflowTemplateResponse, error)
- type Job
- type LaunchJobTemplateRequest
- type LaunchJobTemplateResponse
- type LaunchWorkflowTemplateRequest
- type LaunchWorkflowTemplateResponse
- type MethodNotAllowedError
- type NotFoundError
- type Template
- type TemplateType
Constants ¶
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 ¶
NewClient creates a new AAP API client. When insecureSkipVerify is true, TLS certificate verification is disabled (InsecureSkipVerify) for AAP API requests.
func (*Client) CanCancelJob ¶
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 ¶
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) GetTemplate ¶
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 ¶
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 ¶
func (c *Client) LaunchJobTemplate(ctx context.Context, req LaunchJobTemplateRequest) (*LaunchJobTemplateResponse, error)
LaunchJobTemplate launches a job template and returns the job ID.
func (*Client) LaunchWorkflowTemplate ¶
func (c *Client) LaunchWorkflowTemplate(ctx context.Context, req LaunchWorkflowTemplateRequest) (*LaunchWorkflowTemplateResponse, error)
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 ¶
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 ¶
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 ¶
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 ¶
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" )