I have variables in the yaml file and jinja2 template as below.
#consul_common.yml
preprod:
config_token: "SomeTestToken"
#config.env.j2
service_config_token={{ config_token }}
playbook is like below:
---
- hosts: all
gather_facts: yes
tasks:
- include_vars: consul_common.yml
- set_fact:
config_token: "{{ (deploy_environment | lower) }}['config_token']"
- debug:
var: "{{ config_token }}"
- template:
src: config.env.j2
dest: /apps/account-service/config.env
When I run the playbook passing extra env variable deploy_environment=PREPROD
, debug is giving the right variable value i.e. "SomeTestToken"
but when its templated out in jinja2 template, this is what I am getting in /apps/account-service/config.env
service_config_token=preprod['consul_config_token']
I was expecting the content to be : service_config_token=SomeTestToken
tried with this "{{ (deploy_environment | lower)['config_token'] }}"
, did not work either.