Create default EE as a part of create_preload_data

This commit is contained in:
Shane McDonald
2021-02-03 17:06:14 -05:00
parent 57b317d440
commit 428f8addf8
2 changed files with 66 additions and 53 deletions

View File

@@ -2,22 +2,22 @@
# All Rights Reserved # All Rights Reserved
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings
from crum import impersonate from crum import impersonate
from awx.main.models import User, Organization, Project, Inventory, CredentialType, Credential, Host, JobTemplate from awx.main.models import (
User, Organization, Project, Inventory, CredentialType,
Credential, Host, JobTemplate, ExecutionEnvironment
)
from awx.main.signals import disable_computed_fields from awx.main.signals import disable_computed_fields
class Command(BaseCommand): class Command(BaseCommand):
"""Create preloaded data, intended for new installs """Create preloaded data, intended for new installs
""" """
help = 'Creates a preload tower data iff there is none.' help = 'Creates a preload tower data if there is none.'
def handle(self, *args, **kwargs): def handle(self, *args, **kwargs):
# Sanity check: Is there already an organization in the system? changed = False
if Organization.objects.count():
print('An organization is already in the system, exiting.')
print('(changed: False)')
return
# Create a default organization as the first superuser found. # Create a default organization as the first superuser found.
try: try:
@@ -26,44 +26,62 @@ class Command(BaseCommand):
superuser = None superuser = None
with impersonate(superuser): with impersonate(superuser):
with disable_computed_fields(): with disable_computed_fields():
o = Organization.objects.create(name='Default') if not Organization.objects.exists():
p = Project(name='Demo Project', o = Organization.objects.create(name='Default')
scm_type='git',
scm_url='https://github.com/ansible/ansible-tower-samples', p = Project(name='Demo Project',
scm_update_on_launch=True, scm_type='git',
scm_update_cache_timeout=0, scm_url='https://github.com/ansible/ansible-tower-samples',
organization=o) scm_update_on_launch=True,
p.save(skip_update=True) scm_update_cache_timeout=0,
ssh_type = CredentialType.objects.filter(namespace='ssh').first() organization=o)
c = Credential.objects.create(credential_type=ssh_type, p.save(skip_update=True)
name='Demo Credential',
inputs={ ssh_type = CredentialType.objects.filter(namespace='ssh').first()
'username': superuser.username c = Credential.objects.create(credential_type=ssh_type,
}, name='Demo Credential',
created_by=superuser) inputs={
c.admin_role.members.add(superuser) 'username': superuser.username
public_galaxy_credential = Credential( },
name='Ansible Galaxy', created_by=superuser)
managed_by_tower=True,
credential_type=CredentialType.objects.get(kind='galaxy'), c.admin_role.members.add(superuser)
inputs = {
'url': 'https://galaxy.ansible.com/' public_galaxy_credential = Credential(name='Ansible Galaxy',
} managed_by_tower=True,
) credential_type=CredentialType.objects.get(kind='galaxy'),
public_galaxy_credential.save() inputs={'url': 'https://galaxy.ansible.com/'})
o.galaxy_credentials.add(public_galaxy_credential) public_galaxy_credential.save()
i = Inventory.objects.create(name='Demo Inventory', o.galaxy_credentials.add(public_galaxy_credential)
organization=o,
created_by=superuser) i = Inventory.objects.create(name='Demo Inventory',
Host.objects.create(name='localhost', organization=o,
inventory=i, created_by=superuser)
variables="ansible_connection: local\nansible_python_interpreter: '{{ ansible_playbook_python }}'",
created_by=superuser) Host.objects.create(name='localhost',
jt = JobTemplate.objects.create(name='Demo Job Template', inventory=i,
playbook='hello_world.yml', variables="ansible_connection: local\nansible_python_interpreter: '{{ ansible_playbook_python }}'",
project=p, created_by=superuser)
inventory=i)
jt.credentials.add(c) jt = JobTemplate.objects.create(name='Demo Job Template',
print('Default organization added.') playbook='hello_world.yml',
print('Demo Credential, Inventory, and Job Template added.') project=p,
print('(changed: True)') inventory=i)
jt.credentials.add(c)
print('Default organization added.')
print('Demo Credential, Inventory, and Job Template added.')
changed = True
default_ee = settings.AWX_EXECUTION_ENVIRONMENT_DEFAULT_IMAGE
ee, created = ExecutionEnvironment.objects.get_or_create(name='Default EE', defaults={'image': default_ee,
'managed_by_tower': True})
if created:
changed = True
print('Default Execution Environment registered.')
if changed:
print('(changed: True)')
else:
print('(changed: False)')

View File

@@ -26,8 +26,3 @@ make init
mkdir -p /awx_devel/awx/public/static mkdir -p /awx_devel/awx/public/static
mkdir -p /awx_devel/awx/ui/static mkdir -p /awx_devel/awx/ui/static
mkdir -p /awx_devel/awx/ui_next/build/static mkdir -p /awx_devel/awx/ui_next/build/static
echo "ee, created = ExecutionEnvironment.objects.get_or_create(name='Default EE', \
defaults={'image': 'quay.io/ansible/awx-ee', \
'managed_by_tower': True}); \
print('Already exists' if not created else 'Created')" | awx-manage shell_plus --quiet-load