mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 04:31:21 -03:30
Merge pull request #11562 from ansible/avoid_dups_create_preload_data
Avoid duplicated entries when calling create_preload_data
This commit is contained in:
commit
381e75b913
@ -23,44 +23,50 @@ class Command(BaseCommand):
|
||||
with impersonate(superuser):
|
||||
with disable_computed_fields():
|
||||
if not Organization.objects.exists():
|
||||
o = Organization.objects.create(name='Default')
|
||||
o, _ = Organization.objects.get_or_create(name='Default')
|
||||
|
||||
p = Project(
|
||||
p, _ = Project.objects.get_or_create(
|
||||
name='Demo Project',
|
||||
scm_type='git',
|
||||
scm_url='https://github.com/ansible/ansible-tower-samples',
|
||||
scm_update_on_launch=True,
|
||||
scm_update_cache_timeout=0,
|
||||
organization=o,
|
||||
)
|
||||
p.organization = o
|
||||
p.save(skip_update=True)
|
||||
|
||||
ssh_type = CredentialType.objects.filter(namespace='ssh').first()
|
||||
c = Credential.objects.create(
|
||||
c, _ = Credential.objects.get_or_create(
|
||||
credential_type=ssh_type, name='Demo Credential', inputs={'username': superuser.username}, created_by=superuser
|
||||
)
|
||||
|
||||
c.admin_role.members.add(superuser)
|
||||
|
||||
public_galaxy_credential = Credential(
|
||||
public_galaxy_credential, _ = Credential.objects.get_or_create(
|
||||
name='Ansible Galaxy',
|
||||
managed=True,
|
||||
credential_type=CredentialType.objects.get(kind='galaxy'),
|
||||
inputs={'url': 'https://galaxy.ansible.com/'},
|
||||
)
|
||||
public_galaxy_credential.save()
|
||||
o.galaxy_credentials.add(public_galaxy_credential)
|
||||
|
||||
i = Inventory.objects.create(name='Demo Inventory', organization=o, created_by=superuser)
|
||||
i, _ = Inventory.objects.get_or_create(name='Demo Inventory', organization=o, created_by=superuser)
|
||||
|
||||
Host.objects.create(
|
||||
Host.objects.get_or_create(
|
||||
name='localhost',
|
||||
inventory=i,
|
||||
variables="ansible_connection: local\nansible_python_interpreter: '{{ ansible_playbook_python }}'",
|
||||
created_by=superuser,
|
||||
)
|
||||
|
||||
jt = JobTemplate.objects.create(name='Demo Job Template', playbook='hello_world.yml', project=p, inventory=i)
|
||||
jt = JobTemplate.objects.filter(name='Demo Job Template').first()
|
||||
if jt:
|
||||
jt.project = p
|
||||
jt.inventory = i
|
||||
jt.playbook = 'hello_world.yml'
|
||||
jt.save()
|
||||
else:
|
||||
jt, _ = JobTemplate.objects.get_or_create(name='Demo Job Template', playbook='hello_world.yml', project=p, inventory=i)
|
||||
jt.credentials.add(c)
|
||||
|
||||
print('Default organization added.')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user