def write_ansible_playbook(self, f5server=None, f5user=None, f5password=None): """ Create the ansible playbook based on output json :param f5server: Ip of f5 server :param f5user: username for f5 :param f5password: password for f5 :return: None """ ansible_traffic_path = '%s/avi_migrate_and_verfiy_traffic.yml' \ % self.outdir ansible_create_object_path = '%s/avi_config_create_object.yml'\ % self.outdir # Get the reference object list for not_in_use tag. inuse_list = [] if not self.not_in_use: inuse_list = filter_for_vs(self.avi_cfg) ad = deepcopy(ansible_dict) generate_traffic_dict = deepcopy(ansible_dict) meta = self.avi_cfg['META'] if 'order' not in meta: meta['order'] = self.default_meta_order for obj_type in meta['order']: if self.filter_types and obj_type not in self.filter_types: continue if obj_type not in self.avi_cfg or obj_type in self.skip_types: continue self.build_ansible_objects(obj_type, self.avi_cfg[obj_type], ad, inuse_list) # if f5 username, password and server present then only generate # playbook for traffic. if f5server and f5user and f5password: self.generate_traffic(generate_traffic_dict, f5server, f5user, f5password) # Generate traffic file separately with open(ansible_traffic_path, "w+") as outf: outf.write(ANSIBLE_STR) outf.write('---\n') yaml.safe_dump([generate_traffic_dict], outf, default_flow_style=False, indent=2) with open(ansible_create_object_path, "w+") as outf: outf.write(ANSIBLE_STR) outf.write('---\n') yaml.safe_dump([ad], outf, default_flow_style=False, indent=2)
def write_ansible_playbook(self, f5server=None, f5user=None, f5password=None): """ Create the ansible playbook based on output json :param f5server: Ip of f5 server :param f5user: username for f5 :param f5password: password for f5 :return: None """ ansible_traffic_path = '%s/avi_migrate_and_verfiy_traffic.yml' \ % self.outdir ansible_create_object_path = '%s/avi_config_create_object.yml'\ % self.outdir # Get the reference object list for not_in_use tag. inuse_list = [] if not self.not_in_use: inuse_list = filter_for_vs(self.avi_cfg) ad = deepcopy(ansible_dict) generate_traffic_dict = deepcopy(ansible_dict) meta = self.avi_cfg['META'] if 'order' not in meta: meta['order'] = self.default_meta_order for obj_type in meta['order']: if self.filter_types and obj_type not in self.filter_types: continue if obj_type not in self.avi_cfg or obj_type in self.skip_types: continue self.build_ansible_objects(obj_type, self.avi_cfg[obj_type], ad, inuse_list) # if f5 username, password and server present then only generate # playbook for traffic. if f5server and f5user and f5password: self.generate_traffic(generate_traffic_dict, f5server, f5user, f5password) # Generate traffic file separately with open(ansible_traffic_path, "w+") as outf: outf.write(ANSIBLE_STR) outf.write('---\n') yaml.safe_dump( [generate_traffic_dict], outf, default_flow_style=False, indent=2 ) with open(ansible_create_object_path, "w+") as outf: outf.write(ANSIBLE_STR) outf.write('---\n') yaml.safe_dump([ad], outf, default_flow_style=False, indent=2)
def write_ansible_playbook(self, f5server=None, f5user=None, f5password=None, instance_type=None): """ Create the ansible playbook based on output json :param f5server: Ip of f5 server :param f5user: username for f5 :param f5password: password for f5 :return: None """ ansible_traffic_path = '%s/avi_migrate_and_verfiy_traffic.yml' \ % self.outdir ansible_create_object_path = '%s/avi_config_create_object.yml'\ % self.outdir ansible_delete_object_path = '%s/avi_config_delete_object.yml'\ % self.outdir # Get the reference object list for not_in_use tag. inuse_list = [] if not self.not_in_use: inuse_list = filter_for_vs(self.avi_cfg) ad = deepcopy(ansible_dict) generate_traffic_dict = deepcopy(ansible_dict) total_size = len(self.default_meta_order['avi_resource_types']) progressbar_count = 0 print "Conversion Started For Ansible Create Object..." for obj_type in self.default_meta_order['avi_resource_types']: progressbar_count += 1 # Added call to check progress. msg = "Ansible Create Object..." mg_util.print_progress_bar(progressbar_count, total_size, msg, prefix='Progress', suffix='') if self.filter_types and obj_type not in self.filter_types: continue # have a temp dict for accessing lowercase keys avi_cfg_temp = {k.lower(): v for k, v in self.avi_cfg.items()} if obj_type not in avi_cfg_temp or obj_type in self.skip_types: continue self.build_ansible_objects(obj_type, avi_cfg_temp[obj_type], ad, inuse_list) # if f5 username, password and server present then only generate # playbook for traffic. if f5server and f5user and f5password and instance_type: self.generate_traffic(generate_traffic_dict, f5server, f5user, f5password, instance_type) # Generate traffic file separately with open(ansible_traffic_path, "w+") as outf: outf.write(ANSIBLE_STR) outf.write('---\n') yaml.safe_dump([generate_traffic_dict], outf, default_flow_style=False, indent=2) with open(ansible_create_object_path, "w") as outf: outf.write(ANSIBLE_STR) outf.write('---\n') yaml.safe_dump([ad], outf, default_flow_style=False, indent=2) # Added support to generate ansible delete object playbook if len(ad['tasks']): for k, v in ad['tasks'][0].iteritems(): if isinstance(v, dict): v['api_context'] = "{{avi_api_context | default(omit)}}" tasks = [task for task in reversed(ad['tasks'])] for task in tasks: for k, v in task.iteritems(): if k == 'name' or k == 'tags' or k == 'register': continue if v.get('system_default'): tasks.remove(task) continue v['state'] = 'absent' ad['tasks'] = tasks with open(ansible_delete_object_path, "w") as outf: outf.write('# Auto-generated from Avi Configuration\n') outf.write('---\n') yaml.safe_dump([ad], outf, default_flow_style=False, indent=2)
def write_ansible_playbook(self, f5server=None, f5user=None, f5password=None, instance_type=None): """ Create the ansible playbook based on output json :param f5server: Ip of f5 server :param f5user: username for f5 :param f5password: password for f5 :return: None """ ansible_traffic_path = '%s/avi_migrate_and_verfiy_traffic.yml' \ % self.outdir ansible_create_object_path = '%s/avi_config_create_object.yml'\ % self.outdir ansible_delete_object_path = '%s/avi_config_delete_object.yml'\ % self.outdir # Get the reference object list for not_in_use tag. inuse_list = [] if not self.not_in_use: inuse_list = filter_for_vs(self.avi_cfg) ad = deepcopy(ansible_dict) generate_traffic_dict = deepcopy(ansible_dict) total_size = len(self.default_meta_order['avi_resource_types']) progressbar_count = 0 print "Conversion Started For Ansible Create Object..." for obj_type in self.default_meta_order['avi_resource_types']: progressbar_count += 1 # Added call to check progress. msg = "Ansible Create Object..." mg_util.print_progress_bar(progressbar_count, total_size, msg, prefix='Progress', suffix='') if self.filter_types and obj_type not in self.filter_types: continue # have a temp dict for accessing lowercase keys avi_cfg_temp = {k.lower(): v for k, v in self.avi_cfg.items()} if obj_type not in avi_cfg_temp or obj_type in self.skip_types: continue self.build_ansible_objects(obj_type, avi_cfg_temp[obj_type], ad, inuse_list) # if f5 username, password and server present then only generate # playbook for traffic. if f5server and f5user and f5password and instance_type == 'f5': self.generate_traffic(generate_traffic_dict, f5server, f5user, f5password, instance_type) # Generate traffic file separately with open(ansible_traffic_path, "w+") as outf: outf.write(ANSIBLE_STR) outf.write('---\n') yaml.safe_dump( [generate_traffic_dict], outf, default_flow_style=False, indent=2 ) with open(ansible_create_object_path, "w") as outf: outf.write(ANSIBLE_STR) outf.write('---\n') yaml.safe_dump([ad], outf, default_flow_style=False, indent=2) # Added support to generate ansible delete object playbook if len(ad['tasks']): for k, v in ad['tasks'][0].iteritems(): if isinstance(v, dict): v['api_context'] = "{{avi_api_context | default(omit)}}" tasks = [task for task in reversed(ad['tasks'])] for task in tasks: for k, v in task.iteritems(): if k == 'name' or k == 'tags' or k =='register': continue if v.get('system_default'): tasks.remove(task) continue v['state'] = 'absent' ad['tasks'] = tasks with open(ansible_delete_object_path, "w") as outf: outf.write('# Auto-generated from Avi Configuration\n') outf.write('---\n') yaml.safe_dump([ad], outf, default_flow_style=False, indent=2)