mirror of
https://github.com/ansible/awx.git
synced 2026-02-13 14:55:45 -03:30
Fix some issues syncing playbooks
* Build a list of playbooks and store it in the database at sync time * Fix an issue running playbook sync on jobs for scan jobs * Remove a TODO that was unneeded
This commit is contained in:
@@ -961,12 +961,15 @@ class ProjectSerializer(UnifiedJobTemplateSerializer, ProjectOptionsSerializer):
|
|||||||
|
|
||||||
class ProjectPlaybooksSerializer(ProjectSerializer):
|
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:
|
class Meta:
|
||||||
model = Project
|
model = Project
|
||||||
fields = ('playbooks',)
|
fields = ('playbooks',)
|
||||||
|
|
||||||
|
def get_playbooks(self, obj):
|
||||||
|
return obj.playbook_files
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def data(self):
|
def data(self):
|
||||||
ret = super(ProjectPlaybooksSerializer, self).data
|
ret = super(ProjectPlaybooksSerializer, self).data
|
||||||
|
|||||||
20
awx/main/migrations/0044_v310_project_playbook_files.py
Normal file
20
awx/main/migrations/0044_v310_project_playbook_files.py
Normal file
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -7,6 +7,9 @@ import os
|
|||||||
import re
|
import re
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
|
# JSONField
|
||||||
|
from jsonfield import JSONField
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@@ -236,6 +239,14 @@ class Project(UnifiedJobTemplate, ProjectOptions, ResourceMixin):
|
|||||||
help_text=_('The last revision fetched by a project update'),
|
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=[
|
admin_role = ImplicitRoleField(parent_role=[
|
||||||
'organization.admin_role',
|
'organization.admin_role',
|
||||||
'singleton:' + ROLE_SINGLETON_SYSTEM_ADMINISTRATOR,
|
'singleton:' + ROLE_SINGLETON_SYSTEM_ADMINISTRATOR,
|
||||||
|
|||||||
@@ -160,12 +160,6 @@ def tower_periodic_scheduler(self):
|
|||||||
logger.debug("Last run was: %s", last_run)
|
logger.debug("Last run was: %s", last_run)
|
||||||
write_last_run(run_now)
|
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)
|
old_schedules = Schedule.objects.enabled().before(last_run)
|
||||||
for schedule in old_schedules:
|
for schedule in old_schedules:
|
||||||
schedule.save()
|
schedule.save()
|
||||||
@@ -997,7 +991,7 @@ class RunJob(BaseTask):
|
|||||||
return getattr(settings, 'AWX_PROOT_ENABLED', False)
|
return getattr(settings, 'AWX_PROOT_ENABLED', False)
|
||||||
|
|
||||||
def pre_run_hook(self, job, **kwargs):
|
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.project.create_project_update()
|
||||||
local_project_sync.job_type = 'run'
|
local_project_sync.job_type = 'run'
|
||||||
local_project_sync.save()
|
local_project_sync.save()
|
||||||
@@ -1205,12 +1199,13 @@ class RunProjectUpdate(BaseTask):
|
|||||||
return kwargs.get('private_data_files', {}).get('scm_credential', '')
|
return kwargs.get('private_data_files', {}).get('scm_credential', '')
|
||||||
|
|
||||||
def post_run_hook(self, instance, status, **kwargs):
|
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
|
p = instance.project
|
||||||
fd = open('/tmp/_{}_syncrev'.format(instance.id), 'r')
|
fd = open('/tmp/_{}_syncrev'.format(instance.id), 'r')
|
||||||
lines = fd.readlines()
|
lines = fd.readlines()
|
||||||
if lines:
|
if lines:
|
||||||
p.scm_revision = lines[0].strip()
|
p.scm_revision = lines[0].strip()
|
||||||
|
p.playbook_files = p.playbooks
|
||||||
p.save()
|
p.save()
|
||||||
else:
|
else:
|
||||||
logger.error("Could not find scm revision in check")
|
logger.error("Could not find scm revision in check")
|
||||||
|
|||||||
@@ -29,8 +29,8 @@
|
|||||||
version: "{{scm_branch|quote}}"
|
version: "{{scm_branch|quote}}"
|
||||||
force: "{{scm_clean}}"
|
force: "{{scm_clean}}"
|
||||||
accept_hostkey: "{{scm_accept_hostkey}}"
|
accept_hostkey: "{{scm_accept_hostkey}}"
|
||||||
clone: "{{ scm_full_checkout }}"
|
#clone: "{{ scm_full_checkout }}"
|
||||||
update: "{{ scm_full_checkout }}"
|
#update: "{{ scm_full_checkout }}"
|
||||||
when: scm_type == 'git' and scm_accept_hostkey is defined
|
when: scm_type == 'git' and scm_accept_hostkey is defined
|
||||||
register: scm_result
|
register: scm_result
|
||||||
|
|
||||||
@@ -45,8 +45,8 @@
|
|||||||
repo: "{{scm_url|quote}}"
|
repo: "{{scm_url|quote}}"
|
||||||
version: "{{scm_branch|quote}}"
|
version: "{{scm_branch|quote}}"
|
||||||
force: "{{scm_clean}}"
|
force: "{{scm_clean}}"
|
||||||
clone: "{{ scm_full_checkout }}"
|
#clone: "{{ scm_full_checkout }}"
|
||||||
update: "{{ scm_full_checkout }}"
|
#update: "{{ scm_full_checkout }}"
|
||||||
when: scm_type == 'git' and scm_accept_hostkey is not defined
|
when: scm_type == 'git' and scm_accept_hostkey is not defined
|
||||||
register: scm_result
|
register: scm_result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user