How to use group_vars method in molecule

Best Python code snippet using molecule_python

main.py

Source:main.py Github

copy

Full Screen

1import os2import re3import yaml4from flask import Blueprint, render_template, request5from functions.bbui import load_yaml,save_yaml6groups = Blueprint('groups', __name__, template_folder='templates')7@groups.route("/inventory/groups/index.html")8def inventory_groups_index():9 return render_template("page.html.j2", page_content_path="groups/index.html", page_title="Inventory - Groups", page_left_menu="groups/menu.html")10### MASTER GROUPS11@groups.route("/inventory/groups/master_groups/index.html", methods = ['GET', 'POST'])12def inventory_groups_master_groups_index():13 if request.method == 'POST':14 print(request.form)15 if "add_master_group_name" in request.form: # From add16 os.system('mkdir /etc/bluebanquise/inventory/group_vars/'+request.form.get('add_master_group_name'))17 save_yaml('/etc/bluebanquise/inventory/group_vars/'+request.form.get('add_master_group_name')+'/mg_data.yml',{'description':request.form.get('add_master_group_description')})18 os.system('touch /etc/bluebanquise/inventory/group_vars/'+request.form.get('add_master_group_name')+'/mg_custom_variables.yml')19 if "manage_master_group_description" in request.form: # From manage20 print(request.args.get('master_group'))21 yaml_buffer = load_yaml('/etc/bluebanquise/inventory/group_vars/'+request.args.get('master_group')+'/mg_data.yml')22 yaml_buffer['description'] = request.form.get('manage_master_group_description')23 save_yaml('/etc/bluebanquise/inventory/group_vars/'+request.args.get('master_group')+'/mg_data.yml',yaml_buffer)24 save_yaml( '/etc/bluebanquise/inventory/group_vars/'+request.args.get('master_group')+'/mg_custom_variables.yml', yaml.safe_load(request.form.get('manage_master_group_variables')) )25 # Gather list of existing master groups26 master_groups_data = {}27 for folder in os.listdir("/etc/bluebanquise/inventory/group_vars/"):28 if re.match('^mg_', folder):29 yaml_buffer = load_yaml('/etc/bluebanquise/inventory/group_vars/' + folder + '/mg_data.yml')30 master_groups_data[folder] = yaml_buffer31 return render_template("page.html.j2", page_content_path="groups/master_groups/index.html", page_title="Inventory - Groups", page_left_menu="groups/menu.html", left_menu_active="master_groups", master_groups_data=master_groups_data)32@groups.route("/inventory/groups/master_groups/add.html")33def inventory_groups_master_groups_add():34 return render_template("page.html.j2", \35 page_content_path="groups/master_groups/add.html", \36 page_title="Inventory - Groups", \37 page_left_menu="groups/menu.html", \38 left_menu_active="master_groups" )39@groups.route("/inventory/groups/master_groups/manage.html", methods = ['GET'])40def inventory_groups_master_groups_manage():41 if request.method == 'GET':42 master_group_data = load_yaml('/etc/bluebanquise/inventory/group_vars/' + request.args.get('master_group') + '/mg_data.yml')43 master_group_custom_variables = load_yaml('/etc/bluebanquise/inventory/group_vars/' + request.args.get('master_group') + '/mg_custom_variables.yml')44 print(master_group_custom_variables)45 return render_template("page.html.j2", page_content_path="groups/master_groups/manage.html", page_title="Inventory - Groups", \46 page_left_menu="groups/menu.html", left_menu_active="master_groups", \47 master_group_data=master_group_data, master_group_custom_variables=yaml.dump(master_group_custom_variables), master_group=request.args.get('master_group') )48### CUSTOM GROUPS49@groups.route("/inventory/groups/custom_groups/index.html", methods = ['GET', 'POST'])50def inventory_groups_custom_groups_index():51 if request.method == 'POST':52 print(request.form)53 if "add_custom_group_name" in request.form: # From add54 os.system('mkdir /etc/bluebanquise/inventory/group_vars/'+request.form.get('add_custom_group_name'))55 save_yaml('/etc/bluebanquise/inventory/group_vars/'+request.form.get('add_custom_group_name')+'/mg_data.yml',{'description':request.form.get('add_custom_group_description')})56 os.system('touch /etc/bluebanquise/inventory/group_vars/'+request.form.get('add_custom_group_name')+'/mg_custom_variables.yml')57 if "manage_custom_group_description" in request.form: # From manage58 print(request.args.get('custom_group'))59 yaml_buffer = load_yaml('/etc/bluebanquise/inventory/group_vars/'+request.args.get('custom_group')+'/mg_data.yml')60 yaml_buffer['description'] = request.form.get('manage_custom_group_description')61 save_yaml('/etc/bluebanquise/inventory/group_vars/'+request.args.get('custom_group')+'/mg_data.yml',yaml_buffer)62 save_yaml( '/etc/bluebanquise/inventory/group_vars/'+request.args.get('custom_group')+'/mg_custom_variables.yml', yaml.safe_load(request.form.get('manage_custom_group_variables')) )63 # Gather list of existing custom groups64 custom_groups_data = {}65 for folder in os.listdir("/etc/bluebanquise/inventory/group_vars/"):66 if re.match('^custom_', folder):67 yaml_buffer = load_yaml('/etc/bluebanquise/inventory/group_vars/' + folder + '/mg_data.yml')68 custom_groups_data[folder] = yaml_buffer69 return render_template("page.html.j2", page_content_path="groups/custom_groups/index.html", page_title="Inventory - Groups", page_left_menu="groups/menu.html", left_menu_active="custom_groups", custom_groups_data=custom_groups_data)70@groups.route("/inventory/groups/custom_groups/add.html")71def inventory_groups_custom_groups_add():72 return render_template("page.html.j2", \73 page_content_path="groups/custom_groups/add.html", \74 page_title="Inventory - Groups", \75 page_left_menu="groups/menu.html", \76 left_menu_active="custom_groups" )77@groups.route("/inventory/groups/custom_groups/manage.html", methods = ['GET'])78def inventory_groups_custom_groups_manage():79 if request.method == 'GET':80 custom_group_data = load_yaml('/etc/bluebanquise/inventory/group_vars/' + request.args.get('custom_group') + '/mg_data.yml')81 custom_group_custom_variables = load_yaml('/etc/bluebanquise/inventory/group_vars/' + request.args.get('custom_group') + '/mg_custom_variables.yml')82 print(custom_group_custom_variables)83 return render_template("page.html.j2", page_content_path="groups/custom_groups/manage.html", page_title="Inventory - Groups", \84 page_left_menu="groups/menu.html", left_menu_active="custom_groups", \85 custom_group_data=custom_group_data, custom_group_custom_variables=yaml.dump(custom_group_custom_variables), custom_group=request.args.get('custom_group') )86### EQUIPMENT_PROFILES87@groups.route("/inventory/groups/equipment_profile/index.html", methods = ['GET', 'POST'])88def inventory_groups_equipment_profile_groups_index():89 if request.method == 'POST':90 if "add_equipment_profile_group_name" in request.form:91 os.system('mkdir /etc/bluebanquise/inventory/group_vars/'+request.form.get('add_equipment_profile_group_name'))92 save_yaml('/etc/bluebanquise/inventory/group_vars/'+request.form.get('add_equipment_profile_group_name')+'/ep_data.yml',{'description':request.form.get('add_equipment_profile_group_description')})93 # Gather list of existing equipment_profile groups94 equipment_profile_groups_data = {}95 for folder in os.listdir("/etc/bluebanquise/inventory/group_vars/"):96 if re.match('^equipment_', folder):97 yaml_buffer = load_yaml('/etc/bluebanquise/inventory/group_vars/' + folder + '/ep_data.yml')98 equipment_profile_groups_data[folder] = yaml_buffer99 print(equipment_profile_groups_data)100 return render_template("page.html.j2", page_content_path="groups/equipment_profile/index.html", page_title="Inventory - Groups", page_left_menu="groups/menu.html", left_menu_active="equipment_profile_groups", equipment_profile_groups_data=equipment_profile_groups_data)101@groups.route("/inventory/groups/equipment_profile/add.html")102def inventory_groups_equipment_profile_groups_add():...

Full Screen

Full Screen

generate_vars.py

Source:generate_vars.py Github

copy

Full Screen

1#!/usr/bin/env python2.72import sys, os3import re4group_var_all = "group_vars/all/vars.yml"5# These are multiline variables, need to be formatted correctly as yaml.6# There will be some sort of whitespace, explicity change that whitespace to7# newline and correct indentation.8force_multiline = [9 "c2e_edge_vm_ssh_priv_key",10 "c2e_edge_vm_ssh_pub_key"11]12def emit_var(key, value, vars_file):13 if key in force_multiline:14 lines = value.splitlines()15 vars_file.write("%s: |\n" % key.lower())16 for line in lines:17 vars_file.write(" %s\n" % line)18 else:19 vars_file.write("%s: %s\n" % (key.lower(), value))20def generate_vars(args=None):21 if not os.path.exists(os.path.dirname(group_var_all)):22 os.makedirs(os.path.dirname(group_var_all))23 group_vars = open(group_var_all, "w")24 group_vars.write("---\n")25 for k, v in os.environ.items():26 # Emit our own variables27 if re.search("^c2e", k, re.IGNORECASE):28 emit_var(k, v, group_vars)29 # Emit variables for cloud providers30 elif re.search("^aws", k, re.IGNORECASE):31 emit_var(k, v, group_vars)32 elif re.search("^azure", k, re.IGNORECASE):33 emit_var(k, v, group_vars)34 elif re.search("^google", k, re.IGNORECASE):35 emit_var(k, v, group_vars)36 elif re.search("^ibm", k, re.IGNORECASE):37 emit_var(k, v, group_vars)38 elif re.search("^greengrass", k, re.IGNORECASE):39 emit_var(k, v, group_vars)40 elif re.search(".*s3.*", k, re.IGNORECASE):41 emit_var(k, v, group_vars)42 elif re.search(".*lambda.*", k, re.IGNORECASE):43 emit_var(k, v, group_vars)44 # Some special cases; variables that aren't named according to45 # convention but that we need anyway.46 elif re.search("base_.*", k, re.IGNORECASE):47 emit_var(k, v, group_vars)48 elif re.search("binary_.*", k, re.IGNORECASE):49 emit_var(k, v, group_vars)50 group_vars.close()51if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run molecule automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful