#!/usr/bin/python#Coding:utf-8""""""ImportSys,os fromContextlibImportnestedprofilelist= {};defPropValue (envfile): with open (Envfile) as Profile:new_profile=Profile.readlines (); forLineinchNew_profile:line_key= Line.strip (). Split ("=", 1) [0]; Profilelist[line_key]= Line.strip (). Split ("=", 1) [1]; defEnvreplaceyaml (yamlfile,newyamlfile):Try: With nested (open (Yamlfile), open (Newyamlfile,'W') as (Yml_file, yml_output): Yml_file_lines=Yml_file.readlines (); forLineinchYml_file_lines:new_line=Line ; if(New_line.find ('$ $PLACEHOLDER $$') >0): Env_list= New_line.split (':'); Env_name=Env_list[0].strip (); Replacement=""; ifEnv_nameinchProfilelist.keys (): Replacement=Profilelist[env_name]; New_line= New_line.replace ('$ $PLACEHOLDER $$', replacement); Yml_output.write (New_line); exceptIOError, E:Print("Error:"+Format (str (e))); Raise; if __name__=="__main__": PropValue ('Env'); Envreplaceyaml ('Temp.yaml','Newtemap.yaml');
Temp.yaml
---Applications:-Name: $ $NAME $$-$ $DATETIME $$-$ $VERSION $$ memory:2048m instances:1disk_quota:2048m################## ==================================================env:app_id:"$ $PLACEHOLDER $$"Table_key:"$ $PLACEHOLDER $$"SECURITY:"$ $PLACEHOLDER $$"KEY:"$ $PLACEHOLDER $$"
Env
app_id=11111111111 table_key=22222222222 SECURITY=3333333333333 KEY =6777777777777
Replace the variable value "Python" in the Yaml template with the parameter value inside the configuration file