Workflow Job Template

Description

This resource is used for managing workflow job template resources in Tower. It is also responsible for associating/disassociating labels and notification templates to/from an existing job template. There is yet another 2 custom commands, survey, used for getting survey specification of a workflow job template, and schema, used for build workflow topology via YAML/JSON content.

Workflow Schema

Workflow schema is a handy API to bulk-create or bulk-update a workflow node network. The schema is a JSON- or YAML-formatted string defining the hierarchy structure that connects the nodes. Names, as well as other valid parameters for node creation, are acceptable inside of the node’s entry inside the schema definition.

Links must be declared as a list under a key that starts with “success”, “failure”, or “always”. The following is an example of a valid YAML-formatted schema definition.

"""
- job_template: Hello world
  failure:
  - inventory_source: AWS servers (AWS servers - 42)
  success:
  - project: Ansible Examples
    always:
    - job_template: Echo variable
      success:
      - job_template: Scan localhost
"""

The workflow schema feature populates the workflow node network based on the hierarchy structure. Before creating each node, it attempts to find an existing node with the specified properties in that location in the tree, and will not create a new node if it exists. Also, if an existing node has no correspondence in the schema, the entire sub-tree based on that node will be deleted.

Thus, after running the schema command, the resulting workflow node network topology will always be exactly the same as what is specified in the given schema file. To continue with the previous example, subsequent invocations of:

wfjt.schema('workflow1', '<schema spec>')

should not change the network of workflow1, since schema detail is unchanged. However

wfjt.schema('workflow1', '<new schema spec>')

will modify node network topology of workflow1 to exactly the same as what is specified in the new schema spec.

Fields Table

name type help_text read_only unique filterable required
name String The name field. False True True True
description String The description field. False False True False
extra_vars variables Extra variables used by Ansible in YAML or key=value format. Use @ to get YAML from a file. Use the option multiple times to add multiple extra variables. False False True False
organization Resource organization The organization field. False False True False
survey_enabled bool Prompt user for job type on launch. False False True False
allow_simultaneous bool The allow_simultaneous field. False False True False
survey_spec variables On write commands, perform extra POST to the survey_spec endpoint. False False True False

API Specification

class tower_cli.resources.workflow.Resource[source]

A resource for workflow job templates.

associate_label(**kwargs)

Associate a label with this workflow.

Parameters:
  • workflow (str) – Primary key or name of the workflow to associate to.
  • label (str) – Primary key or name of the label to be associated.
Returns:

Dictionary of only one key “changed”, which indicates whether the associate succeeded.

Return type:

dict

associate_label(**kwargs)

Associate a label with this workflow.

Parameters:
  • workflow (str) – Primary key or name of the workflow to associate to.
  • label (str) – Primary key or name of the label to be associated.
Returns:

Dictionary of only one key “changed”, which indicates whether the associate succeeded.

Return type:

dict

associate_notification_template(workflow, notification_template, status)[source]

Associate a notification template from this workflow job template.

Parameters:
  • workflow (str) – The workflow job template to associate to.
  • notification_template (str) – The notification template to be associated.
  • status (str) – type of notification this notification template should be associated to.
Returns:

Dictionary of only one key “changed”, which indicates whether the association succeeded.

Return type:

dict

copy(pk=None, new_name=None, **kwargs)[source]

Copy an object.

Parameters:
  • pk (int) – Primary key of the resource object to be copied
  • new_name – The new name to give the resource if deep copying via the API
  • **kwargs – Keyword arguments of fields whose given value will override the original value.
Returns:

loaded JSON of the copied new resource object.

Return type:

dict

create(**kwargs)[source]

Create an object.

Parameters:
  • fail_on_found (bool) – Flag that if set, the operation fails if an object matching the unique criteria already exists.
  • force_on_exists (bool) – Flag that if set, then if a match is found on unique fields, other fields will be updated to the provided values.; If unset, a match causes the request to be a no-op.
  • **kwargs – Keyword arguments which, all together, will be used as POST body to create the resource object.
Returns:

A dictionary combining the JSON output of the created resource, as well as two extra fields: “changed”, a flag indicating if the resource is created successfully; “id”, an integer which is the primary key of the created object.

Return type:

dict

delete(pk=None, fail_on_missing=False, **kwargs)

Remove the given object.

Parameters:
  • pk (int) – Primary key of the resource to be deleted.
  • fail_on_missing (bool) – Flag that if set, the object’s not being found is considered a failure; otherwise, a success with no change is reported.
  • **kwargs – Keyword arguments used to look up resource object to delete if pk is not provided.
Returns:

dictionary of only one field “changed”, which is a flag indicating whether the specified resource is successfully deleted.

Return type:

dict

disassociate_label(**kwargs)

Disassociate a label with this workflow.

Parameters:
  • workflow (str) – Primary key or name of the workflow to disassociate to.
  • label (str) – Primary key or name of the label to be disassociated.
Returns:

Dictionary of only one key “changed”, which indicates whether the disassociate succeeded.

Return type:

dict

disassociate_notification_template(workflow, notification_template, status)[source]

Disassociate a notification template from this workflow job template.

Parameters:
  • job_template (str) – The workflow job template to disassociate from.
  • notification_template (str) – The notification template to be disassociated.
  • status (str) – type of notification this notification template should be disassociated from.
Returns:

Dictionary of only one key “changed”, which indicates whether the disassociation succeeded.

Return type:

dict

get(pk=None, **kwargs)

Retrieve one and exactly one object.

Parameters:
  • pk (int) – Primary key of the resource to be read. Tower CLI will only attempt to read that object if pk is provided (not None).
  • **kwargs – Keyword arguments used to look up resource object to retrieve if pk is not provided.
Returns:

loaded JSON of the retrieved resource object.

Return type:

dict

list(all_pages=False, **kwargs)

Retrieve a list of objects.

Parameters:
  • all_pages (bool) – Flag that if set, collect all pages of content from the API when returning results.
  • page (int) – The page to show. Ignored if all_pages is set.
  • query (list) – Contains 2-tuples used as query parameters to filter resulting resource objects.
  • **kwargs – Keyword arguments list of available fields used for searching resource objects.
Returns:

A JSON object containing details of all resource objects returned by Tower backend.

Return type:

dict

modify(pk=None, create_on_missing=False, **kwargs)[source]

Modify an already existing object.

Parameters:
  • pk (int) – Primary key of the resource to be modified.
  • create_on_missing (bool) – Flag that if set, a new object is created if pk is not set and objects matching the appropriate unique criteria is not found.
  • **kwargs – Keyword arguments which, all together, will be used as PATCH body to modify the resource object. if pk is not set, key-value pairs of **kwargs which are also in resource’s identity will be used to lookup existing reosource.
Returns:

A dictionary combining the JSON output of the modified resource, as well as two extra fields: “changed”, a flag indicating if the resource is successfully updated; “id”, an integer which is the primary key of the updated object.

Return type:

dict

schema(wfjt, node_network=None)[source]

Convert YAML/JSON content into workflow node objects if node_network param is given. If not, print a YAML representation of the node network.

Parameters:
  • wfjt (str) – Primary key or name of the workflow job template to run schema against.
  • node_network (str) – JSON- or YAML-formatted string representing the topology of the workflow job template be updated to.
Returns:

The latest topology (possibly after modification) of the workflow job template.

Return type:

dict

survey(pk=None, **kwargs)

Get the survey specification of a resource object.

Parameters:
  • pk (int) – Primary key of the resource to retrieve survey from. Tower CLI will only attempt to read that object if pk is provided (not None).
  • **kwargs – Keyword arguments used to look up resource object to retrieve survey if pk is not provided.
Returns:

loaded JSON of the retrieved survey specification of the resource object.

Return type:

dict