0

I am using python jinja2 to render some json files for CI/CD. These files will be used by application which are written in GoLang.

variables are defined a yaml files & loaded using pyymal. For example..

template

{ 
"enable_log": {{ enable_log}}  
}

variable file:

---
us-east-2:
 dev:
    enable_log: true 
 prod:
    enable_log: false
  

The result is as following

{ "enable_log": True }

code snippet:

template_env = Environment(loader=FileSystemLoader(cfg_dir), trim_blocks=True,
                                           lstrip_blocks=True, undefined=StrictUndefined)

source_template = template_env.get_template(cfg_template)

config_data = yaml.load(open(VARS))

with open(out_file, 'w') as f:
    data = source_template.render(config_data[region][env])
    f.write(data)

I know python booleans are True & False. But the application code(Golang) is not loading that as boolean. Is there any workaround in the pyyaml to fix this problem?

Pasha
  • 170
  • 1
  • 19
  • does this help you: https://stackoverflow.com/questions/8433450/why-doesnt-my-condition-logic-work-as-expected-in-jinja2-cherrypy – Kirtiman Sinha Aug 26 '20 at 19:03

1 Answers1

3

This is fixed. Solution is to use the yaml.BaseLoader

config_data = yaml.load(open(VARS), Loader=yaml.BaseLoader)
Pasha
  • 170
  • 1
  • 19