Access the dictionary using another variable as a YAML key

My requirements are as follows: the deployment environment is transferred to the playbook as additional vars, for example: dev, qa or prod

I have a variable called DEPLOY_URL

Depending on the value of the env variable, DEPLOY_URL should change.

I tried to do the following:

DEPLOY_URLS: 
   "dev": "xyz"
   "prod" : "abc"
   "qa" : "123"

DEPLOY_URL: "{{DEPLOY_URLS['{{DEPLOY_ENV}}']}}"

The value will never be right. Is there a way to access the dictionary using another variable as a key? (Using YAML and possibly)

+4
source share
1 answer

Try the following: DEPLOY_URL: "{{ DEPLOY_URLS[DEPLOY_ENV] }}"

+7
source

Source: https://habr.com/ru/post/1657765/


All Articles