Require group when launching new servers

Every host now requires a group, this is mostly because of how our
windmill playbooks are written.

Change-Id: Ia1f54ac6b43e70d5e3474a333343f3ed707b4d7d
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2019-02-27 14:45:01 -05:00
parent 0465f83c48
commit 1210a83ee4

View File

@ -63,7 +63,7 @@ class AnsibleRunner(object):
shutil.rmtree(self.root) shutil.rmtree(self.root)
def bootstrap_server(server, key, name, keep, timeout): def bootstrap_server(server, key, name, group, keep, timeout):
ip = server.public_v4 ip = server.public_v4
ssh_kwargs = dict(pkey=key) ssh_kwargs = dict(pkey=key)
ansible_user = None ansible_user = None
@ -86,8 +86,10 @@ def bootstrap_server(server, key, name, keep, timeout):
with open(runner.hosts, 'w') as inventory_file: with open(runner.hosts, 'w') as inventory_file:
inventory_file.write( inventory_file.write(
"{host} ansible_host={ip} ansible_user={user}".format( "[{group}]\n{host} ansible_host={ip} "\
host=name, ip=server.interface_ip, user=ansible_user)) "ansible_user={user}".format(
group=group,host=name, ip=server.interface_ip,
user=ansible_user))
project_dir = os.path.join( project_dir = os.path.join(
SCRIPT_DIR, '..', 'playbooks', 'bootstrap-ansible') SCRIPT_DIR, '..', 'playbooks', 'bootstrap-ansible')
@ -103,7 +105,7 @@ def bootstrap_server(server, key, name, keep, timeout):
raise Exception("Ansible runner failed") raise Exception("Ansible runner failed")
def build_server(cloud, name, image, flavor, def build_server(cloud, name, group, image, flavor,
volume, keep, network, boot_from_volume, config_drive, volume, keep, network, boot_from_volume, config_drive,
mount_path, fs_label, availability_zone, environment, mount_path, fs_label, availability_zone, environment,
volume_size, timeout): volume_size, timeout):
@ -145,7 +147,7 @@ def build_server(cloud, name, image, flavor,
server = cloud.get_openstack_vars(server) server = cloud.get_openstack_vars(server)
bootstrap_server(server, key, name, keep, timeout) bootstrap_server(server, key, name, group, keep, timeout)
except Exception: except Exception:
print("****") print("****")
@ -171,6 +173,7 @@ def build_server(cloud, name, image, flavor,
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("name", help="server name") parser.add_argument("name", help="server name")
parser.add_argument("group", help="server group")
parser.add_argument("--cloud", dest="cloud", required=True, parser.add_argument("--cloud", dest="cloud", required=True,
help="cloud name") help="cloud name")
parser.add_argument("--region", dest="region", parser.add_argument("--region", dest="region",
@ -244,7 +247,7 @@ def main():
print(i.name) print(i.name)
sys.exit(1) sys.exit(1)
server = build_server(cloud, options.name, image, flavor, server = build_server(cloud, options.name, options.group, image, flavor,
options.volume, options.keep, options.volume, options.keep,
options.network, options.boot_from_volume, options.network, options.boot_from_volume,
options.config_drive, options.config_drive,