Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing a dictionary using another variable as key YAML

Tags:

yaml

ansible

My requirements are these: a deployment environment is passed into the playbook as extra vars, for ex : dev, qa or prod

I have a variable called DEPLOY_URL

Based on the value of the env variable, the DEPLOY_URL has to change.

I tried doing the following :

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

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

The value is never correct. Is there a way to access a dictionary using another variable as key? (Using YAML and ansible)

like image 955
Ashwin Narayanan Avatar asked Oct 14 '16 13:10

Ashwin Narayanan


1 Answers

Try this: DEPLOY_URL: "{{ DEPLOY_URLS[DEPLOY_ENV] }}"

like image 171
Konstantin Suvorov Avatar answered Sep 30 '22 12:09

Konstantin Suvorov