diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 5053c5aa96..d6aa39f706 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -961,12 +961,15 @@ class ProjectSerializer(UnifiedJobTemplateSerializer, ProjectOptionsSerializer): class ProjectPlaybooksSerializer(ProjectSerializer): - playbooks = serializers.ReadOnlyField(help_text='Array of playbooks available within this project.') + playbooks = serializers.SerializerMethodField(help_text='Array of playbooks available within this project.') class Meta: model = Project fields = ('playbooks',) + def get_playbooks(self, obj): + return obj.playbook_files + @property def data(self): ret = super(ProjectPlaybooksSerializer, self).data diff --git a/awx/main/migrations/0044_v310_project_playbook_files.py b/awx/main/migrations/0044_v310_project_playbook_files.py new file mode 100644 index 0000000000..cdf059faec --- /dev/null +++ b/awx/main/migrations/0044_v310_project_playbook_files.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import jsonfield.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0043_v310_scm_revision'), + ] + + operations = [ + migrations.AddField( + model_name='project', + name='playbook_files', + field=jsonfield.fields.JSONField(default=[], help_text='List of playbooks found in the project', verbose_name='Playbook Files', editable=False, blank=True), + ), + ] diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index 5686716d73..1e007a7125 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -7,6 +7,9 @@ import os import re import urlparse +# JSONField +from jsonfield import JSONField + # Django from django.conf import settings from django.db import models @@ -236,6 +239,14 @@ class Project(UnifiedJobTemplate, ProjectOptions, ResourceMixin): help_text=_('The last revision fetched by a project update'), ) + playbook_files = JSONField( + blank=True, + default=[], + editable=False, + verbose_name=_('Playbook Files'), + help_text=_('List of playbooks found in the project'), + ) + admin_role = ImplicitRoleField(parent_role=[ 'organization.admin_role', 'singleton:' + ROLE_SINGLETON_SYSTEM_ADMINISTRATOR, diff --git a/awx/main/tasks.py b/awx/main/tasks.py index f834e32ff3..c952cdc83e 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -160,12 +160,6 @@ def tower_periodic_scheduler(self): logger.debug("Last run was: %s", last_run) write_last_run(run_now) - # Sanity check: If this is a secondary machine, there is nothing - # on the schedule. - # TODO: Fix for clustering/ha - if Instance.objects.my_role() == 'secondary': - return - old_schedules = Schedule.objects.enabled().before(last_run) for schedule in old_schedules: schedule.save() @@ -997,7 +991,7 @@ class RunJob(BaseTask): return getattr(settings, 'AWX_PROOT_ENABLED', False) def pre_run_hook(self, job, **kwargs): - if job.project.scm_type: + if job.project and job.project.scm_type: local_project_sync = job.project.create_project_update() local_project_sync.job_type = 'run' local_project_sync.save() @@ -1205,12 +1199,13 @@ class RunProjectUpdate(BaseTask): return kwargs.get('private_data_files', {}).get('scm_credential', '') def post_run_hook(self, instance, status, **kwargs): - if instance.job_type == 'check': + if instance.job_type == 'check' and status not in ('failed', 'canceled',): p = instance.project fd = open('/tmp/_{}_syncrev'.format(instance.id), 'r') lines = fd.readlines() if lines: p.scm_revision = lines[0].strip() + p.playbook_files = p.playbooks p.save() else: logger.error("Could not find scm revision in check") diff --git a/awx/playbooks/project_update.yml b/awx/playbooks/project_update.yml index 9ab7f1a277..30eff5f6bc 100644 --- a/awx/playbooks/project_update.yml +++ b/awx/playbooks/project_update.yml @@ -29,8 +29,8 @@ version: "{{scm_branch|quote}}" force: "{{scm_clean}}" accept_hostkey: "{{scm_accept_hostkey}}" - clone: "{{ scm_full_checkout }}" - update: "{{ scm_full_checkout }}" + #clone: "{{ scm_full_checkout }}" + #update: "{{ scm_full_checkout }}" when: scm_type == 'git' and scm_accept_hostkey is defined register: scm_result @@ -45,8 +45,8 @@ repo: "{{scm_url|quote}}" version: "{{scm_branch|quote}}" force: "{{scm_clean}}" - clone: "{{ scm_full_checkout }}" - update: "{{ scm_full_checkout }}" + #clone: "{{ scm_full_checkout }}" + #update: "{{ scm_full_checkout }}" when: scm_type == 'git' and scm_accept_hostkey is not defined register: scm_result