diff --git a/tower_cli/resources/job_template.py b/tower_cli/resources/job_template.py index 571daf96..dc03ff73 100644 --- a/tower_cli/resources/job_template.py +++ b/tower_cli/resources/job_template.py @@ -119,12 +119,22 @@ class Resource(models.SurveyResource): labels = models.ManyToManyField('label') instance_groups = models.ManyToManyField('instance_group', method_name='ig') - def write(self, *args, **kwargs): + def write(self, pk=None, *args, **kwargs): # Provide a default value for job_type, but only in creation of JT if (kwargs.get('create_on_missing', False) and (not kwargs.get('job_type', None))): kwargs['job_type'] = 'run' - return super(Resource, self).write(*args, **kwargs) + mcred = kwargs.get('credential', None) + ret = super(Resource, self).write(pk=pk, **kwargs) + cred_ids = [c['id'] for c in ret.get('summary_fields', {}).get('credentials', [])] + if mcred and mcred not in cred_ids: + new_pk = ret['id'] + debug.log('Processing deprecated credential field via another request.', header='details') + self._assoc('credentials', new_pk, mcred) + ret = self.read(new_pk) + ret['id'] = new_pk + ret['changed'] = True + return ret @resources.command(use_fields_as_options=False) @click.option('--job-template', type=types.Related('job_template'))