mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
Updating the setup playbook to support instance group installation
* Support instance groups that begin with "rampart_" and automatically group those using celery and data models * Update settings file to appropriately consider instance groups after install and to properly route messages
This commit is contained in:
parent
8db7e15ad0
commit
e1296f6d3a
39
awx/main/management/commands/register_queue.py
Normal file
39
awx/main/management/commands/register_queue.py
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright (c) 2017 Ansible Tower by Red Hat
|
||||
# All Rights Reserved.
|
||||
import sys
|
||||
|
||||
from awx.main.models import Instance, InstanceGroup
|
||||
|
||||
from optparse import make_option
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--queuename', dest='queuename', type='string',
|
||||
help='Queue to create/update'),
|
||||
make_option('--hostnames', dest='hostnames', type='string',
|
||||
help='List of hosts to add to the queue'),
|
||||
)
|
||||
|
||||
def handle(self, **options):
|
||||
ig = InstanceGroup.objects.filter(name=options.get('queuename'))
|
||||
if ig.exists():
|
||||
print("Instance Group already registered {}".format(ig[0]))
|
||||
ig = ig[0]
|
||||
else:
|
||||
print("Creating instance group {}".format(options.get('queuename')))
|
||||
ig = InstanceGroup(name=options.get('queuename'))
|
||||
ig.save()
|
||||
instance_list = [x.strip() for x in options.get('hostnames').split(",")]
|
||||
for inst_name in instance_list:
|
||||
instance = Instance.objects.filter(hostname=inst_name)
|
||||
if instance.exists() and instance not in ig.instances:
|
||||
ig.instances.add(instance)
|
||||
print("Added instance {} to {}".format(instance, ig))
|
||||
elif not instance.exists():
|
||||
print("Instance does not exist: {}".format(instance))
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("Instance already registered {}".format(instance))
|
||||
Loading…
x
Reference in New Issue
Block a user