Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exported Workflow Job Templates refer to inventories by id instead of natural key #7798

Closed
zedr opened this issue Aug 3, 2020 · 1 comment

Comments

@zedr
Copy link

zedr commented Aug 3, 2020

ISSUE TYPE
  • The API endpoint for a workflow_job_template does not provide a representation that includes the natural key of the related Inventory, which is problematic when migrating it between different instances of AWX/Tower.
SUMMARY

The API endpoint for a workflow_job_template does not provide a representation that includes the natural key of the related Inventory, if set. Instead, it just uses the numerical id, which is problematic when attempting to export and import the workflow between different instances of AWX/Tower, since the API will attempt to use the given numerical id to associate an inventory to the import workflow, which will most likely be different on the target instance of AWX/Tower. This behaviour is dangerous because if the target instance of AWX/Tower has a different inventory with the same numerical id, no warnings will be raised, causing the workflow to be associated with the wrong template.

ENVIRONMENT
  • AWX version: 3.7.1 (Tower)
  • AWX install method: openshift
  • Ansible version: 2.9.9
  • Operating System: OpenShift
  • Web Browser: Google Chrome
STEPS TO REPRODUCE
  1. Export a workflow_job_template that is associated with an inventory
  2. Observe the value of the workflow_job_templates.[].inventory attribut in the exported YAML.
EXPECTED RESULTS

It is reasonable to expect that the following YAML document would be generated for an example workflow_job_template object.

workflow_job_templates:
- allow_simultaneous: true
  ask_inventory_on_launch: false
  ask_limit_on_launch: false
  ask_scm_branch_on_launch: true
  ask_variables_on_launch: true
  description: My VM provisioning
  extra_vars: ''
  inventory:
    name: my-vms
    type: inventory
    organization:
       name: ACME
       type: organization
  limit: null
  name: my-workflow
  natural_key:
    name: my-workflow
    organization:
      name: ACME
      type: organization
    type: workflow_job_template
  organization:
    name: ACME
    type: organization
  related:
    notification_templates_approvals: []
    notification_templates_error: []
    notification_templates_started: []
    notification_templates_success: []
    schedules: []
    survey_spec: {}
    workflow_nodes: []
  scm_branch: null
  survey_enabled: false
  webhook_credential: null

The document above, when imported, will generate the association with the inventory correctly on Tower 3.7.1. This is the expected behaviour, relying on the natural key of the object instead of the id.

ACTUAL RESULTS

YAML such as the following is generated:

workflow_job_templates:
- allow_simultaneous: true
  ask_inventory_on_launch: false
  ask_limit_on_launch: false
  ask_scm_branch_on_launch: true
  ask_variables_on_launch: true
  description: My VM provisioning
  extra_vars: ''
  inventory: 29
  limit: null
  name: my-workflow
  natural_key:
    name: my-workflow
    organization:
      name: ACME
      type: organization
    type: workflow_job_template
  organization:
    name: ACME
    type: organization
  related:
    notification_templates_approvals: []
    notification_templates_error: []
    notification_templates_started: []
    notification_templates_success: []
    schedules: []
    survey_spec: {}
    workflow_nodes: []
  scm_branch: null
  survey_enabled: false
  webhook_credential: null

Notice that the inventory key has the value corresponding to the unique id on the source AWX/Tower server. This is not guaranteed to be the same on the target server when the object will be imported.

zedr pushed a commit to zedr/awx that referenced this issue Aug 3, 2020
…nsible#7798

This changeset introduces two changes:

 1. Update the API representation of Workflow Job Templates to use the
 natural key of the Inventory type instead of its id;
 2. Override the related property of the CLI's WorkflowJobTemplate page
 type to patch the related references during the export process,
 allowing the resource to be serialised using the natural key of the
 Inventory type instead of the id.

Change n.2 is a workaround that is used when exporting resources from
AWX/Tower instances that don't have change n.1. It can be removed in the
future.
zedr pushed a commit to zedr/awx that referenced this issue Aug 4, 2020
…nsible#7798

This changeset introduces two changes:

 1. Update the API representation of Workflow Job Templates to use the
 natural key of the Inventory type instead of its id;
 2. Override the related property of the CLI's WorkflowJobTemplate page
 type to patch the related references during the export process,
 allowing the resource to be serialised using the natural key of the
 Inventory type instead of the id.

Change n.2 is a workaround that is used when exporting resources from
AWX/Tower instances that don't have change n.1. It can be removed in the
future.
zedr pushed a commit to zedr/awx that referenced this issue Aug 6, 2020
…nsible#7798

This changeset introduces two changes:

 1. Update the API representation of Workflow Job Templates to use the
 natural key of the Inventory type instead of its id;
 2. Override the related property of the CLI's WorkflowJobTemplate page
 type to patch the related references during the export process,
 allowing the resource to be serialised using the natural key of the
 Inventory type instead of the id.

Change n.2 is a workaround that is used when exporting resources from
AWX/Tower instances that don't have change n.1. It can be removed in the
future.
@squidboylan
Copy link
Contributor

I tested this manually pre-merge so now that the PR is in this should be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants