diff options
author | Harry Huang <huangxiangyu5@huawei.com> | 2017-07-20 20:17:36 +0800 |
---|---|---|
committer | Harry Huang <huangxiangyu5@huawei.com> | 2017-07-24 10:33:30 +0800 |
commit | 069835924120224ec46fc40877c89ac48608a6f5 (patch) | |
tree | 3e5e1e09affa32c648f766872fe441e0ae1d4dd1 /deploy/compass_conf/templates/ansible_installer/openstack_ocata | |
parent | f12c7c6d19eb21cd99690271f4ef71794a24b683 (diff) |
Dynamic Inventory
JIRA: COMPASS-556
1. using dynamic ansible inventory
2. modify Class AnsibleInstaller in compass-tasks
3. modify compass conf to support this behavior
4. specify docker image in /deploy/conf/compass.conf
5. remove clusterhost status update in playbook_done.py
Change-Id: I04079547c8b251571ae4e5b165d3bf425b8913b7
Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
Diffstat (limited to 'deploy/compass_conf/templates/ansible_installer/openstack_ocata')
2 files changed, 72 insertions, 105 deletions
diff --git a/deploy/compass_conf/templates/ansible_installer/openstack_ocata/inventories/HA-ansible-multinodes.tmpl b/deploy/compass_conf/templates/ansible_installer/openstack_ocata/inventories/HA-ansible-multinodes.tmpl index 7cbd66d6..7184d21d 100755 --- a/deploy/compass_conf/templates/ansible_installer/openstack_ocata/inventories/HA-ansible-multinodes.tmpl +++ b/deploy/compass_conf/templates/ansible_installer/openstack_ocata/inventories/HA-ansible-multinodes.tmpl @@ -1,100 +1,74 @@ -#set controllers = $getVar('controller', []) -#set computes = $getVar('compute', []) -#set has = $getVar('ha', []) -#set odls = $getVar('odl', []) -#set onoss = $getVar('onos', []) -#set opencontrails = $getVar('opencontrail', []) -#set ceph_adm_list = $getVar('ceph_adm',[]) -#set ceph_mon_list = $getVar('ceph_mon',[]) -#set ceph_osd_list = $getVar('ceph_osd',[]) +#set inventory_json = $getVar('inventory_json', []) +#!/usr/bin/env python -#if not $isinstance($controllers, list) - #set controllers = [$controllers] -#end if -#if not $isinstance($computes, list) - #set computes = [$computes] -#end if -#if not $isinstance(has, list) - #set has = [has] -#end if -#if not $isinstance(odls, list) - #set odls = [odls] -#end if -#if not $isinstance(onoss, list) - #set onoss = [onoss] -#end if -#if not $isinstance(opencontrails, list) - #set opencontrails = [opencontrails] -#end if -#if not $isinstance(ceph_adm_list, list) - #set ceph_adm_list = [ceph_adm_list] -#end if -#if not $isinstance(ceph_mon_list, list) - #set ceph_mon_list = [ceph_mon_list] -#end if -#if not $isinstance(ceph_osd_list, list) - #set ceph_osd_list = [ceph_osd_list] -#end if +import os +import sys +import copy +import argparse -#set credentials = $getVar('server_credentials', {}) -#set username = $credentials.get('username', 'root') -#set password = $credentials.get('password', 'root') -[controller] -#for controller in $controllers - #set controller_ip = $controller.install.ip - #set controller_hostname = $controller.hostname -$controller_hostname ansible_ssh_host=$controller_ip ansible_ssh_user=$username ansible_ssh_pass=$password -#end for -[compute] -#for compute in $computes - #set compute_ip = $compute.install.ip - #set compute_hostname = $compute.hostname -$compute_hostname ansible_ssh_host=$compute_ip ansible_ssh_user=$username ansible_ssh_pass=$password -#end for -[ha] -#for ha in $has - #set ha_ip = $ha.install.ip - #set ha_hostname = $ha.hostname -$ha_hostname ansible_ssh_host=$ha_ip ansible_ssh_user=$username ansible_ssh_pass=$password -#end for -[odl] -#for odl in $odls - #set odl_ip = $odl.install.ip - #set odl_hostname = $odl.hostname -$odl_hostname ansible_ssh_host=$odl_ip ansible_ssh_user=$username ansible_ssh_pass=$password -#end for -[onos] -#for onos in $onoss - #set onos_ip = $onos.install.ip - #set onos_hostname = $onos.hostname -$onos_hostname ansible_ssh_host=$onos_ip ansible_ssh_user=$username ansible_ssh_pass=$password -#end for -[opencontrail] -#for opencontrail in $opencontrails - #set opencontrail_ip = $opencontrail.install.ip - #set opencontrail_hostname = $opencontrail.hostname -$opencontrail_hostname ansible_ssh_host=$opencontrail_ip ansible_ssh_user=$username ansible_ssh_pass=$password -#end for -[ceph_adm] -#for ceph_adm in $ceph_adm_list - #set ceph_adm_ip = $ceph_adm.install.ip - #set ceph_adm_hostname = $ceph_adm.hostname -$ceph_adm_hostname ansible_ssh_host=$ceph_adm_ip ansible_ssh_user=$username ansible_ssh_pass=$password -#end for -[ceph_mon] -#for ceph_mon in $ceph_mon_list - #set ceph_mon_ip = $ceph_mon.install.ip - #set ceph_mon_hostname = $ceph_mon.hostname -$ceph_mon_hostname ansible_ssh_host=$ceph_mon_ip ansible_ssh_user=$username ansible_ssh_pass=$password -#end for -[ceph_osd] -#for ceph_osd in $ceph_osd_list - #set ceph_osd_ip = $ceph_osd.install.ip - #set ceph_osd_hostname = $ceph_osd.hostname -$ceph_osd_hostname ansible_ssh_host=$ceph_osd_ip ansible_ssh_user=$username ansible_ssh_pass=$password -#end for -[ceph:children] -ceph_adm -ceph_mon -ceph_osd +try: + import json +except ImportError: + import simplejson as json +local_inventory='$inventory_json' + +def _byteify(data, ignore_dicts = False): + if isinstance(data, unicode): + return data.encode('utf-8') + if isinstance(data, list): + return [ _byteify(item, ignore_dicts=True) for item in data ] + if isinstance(data, dict) and not ignore_dicts: + return { + _byteify(key, ignore_dicts=True): _byteify(value, ignore_dicts=True) + for key, value in data.iteritems() + } + return data + +def merge_dict(ldict, rdict, overwrite=True): + if not (ldict and rdict): + return + + if not isinstance(ldict, dict): + raise TypeError('ldict type is %s not dict' % type(ldict)) + + if not isinstance(rdict, dict): + raise TypeError('rdict type is %s not dict' % type(rdict)) + + for key, value in rdict.items(): + if isinstance(value, dict) and key in ldict and isinstance(ldict[key], + dict): + merge_dict(ldict[key], value, overwrite) + else: + if overwrite or key not in ldict: + ldict[key] = copy.deepcopy(value) + +def load_inventory(inventory): + if not os.path.exists(inventory): + raise RuntimeError('file: %s not exist' % inventory) + with open(inventory, 'r') as fd: + return json.load(fd, object_hook=_byteify) + +def dump_inventory(inventory, data): + with open(inventory, 'w') as fd: + json.dump(data, fd, indent=4) + +def merge_inventory(linv, rinv): + ldata = load_inventory(linv) + rdata = load_inventory(rinv) + merge_dict(ldata, rdata, overwrite=True) + dump_inventory(linv, ldata) + +def read_cli_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--list', action = 'store_true') + parser.add_argument('--merge', action = 'store') + return parser.parse_args() + +if __name__ == '__main__': + get_args = read_cli_args() + new_inventory = get_args.merge + if get_args.list: + print load_inventory(local_inventory) + elif new_inventory: + merge_inventory(local_inventory, new_inventory) diff --git a/deploy/compass_conf/templates/ansible_installer/openstack_ocata/vars/HA-ansible-multinodes.tmpl b/deploy/compass_conf/templates/ansible_installer/openstack_ocata/vars/HA-ansible-multinodes.tmpl index 7b0f4ab0..b7b6b91e 100755 --- a/deploy/compass_conf/templates/ansible_installer/openstack_ocata/vars/HA-ansible-multinodes.tmpl +++ b/deploy/compass_conf/templates/ansible_installer/openstack_ocata/vars/HA-ansible-multinodes.tmpl @@ -34,7 +34,6 @@ $res #set $host_info[$host['hostname']] = $info #set $inc = $inc + 1 #end for - host_info: $host_info #set ip_settings={} @@ -51,6 +50,7 @@ host_info: $host_info #set has = $getVar('ha', []) #set ha_vip = $getVar('ha_vip', []) +run_dir: $getVar('run_dir', '') enable_secgroup: $getVar('enable_secgroup', True) enable_fwaas: $getVar('enable_fwaas', True) @@ -187,13 +187,6 @@ CONGRESS_PASS: $congress_pass DEMO_PASS: $demo_pass ADMIN_PASS: $admin_pass -#set plugins = $getVar('plugins', []) -#for item in plugins -#set keys = $item.keys() -#set values = $item.values() -$keys[0]: $values[0] -#end for - #set neutron_service_plugins=['router'] #if $getVar('enable_fwaas', True) |