Dilna Fathima
Dilna Fathima

Reputation: 3

Referencing dictionary values

Global variable group_vars/all.yml

---
dir:
  website_A: /var/www/html/a
  website_B: /var/www/html/b

I have created Ansible role health-check which accepts input variable site, it can have values website_A or website_B. This role will perform some actions based on the input variable site. I tried with the following settings, but it didn't worked.

chdir: "{{ "dir." + site }}"

As per the FAQ, we can make this work using hostvars or vars dictionary, but I didn't succeed in that.

Upvotes: 0

Views: 183

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68229

You have a kind of unbalanced quotes.

Try chdir: "{{ 'dir.' + site }}" or chdir: dir.{{ site }}

Upvotes: 1

Related Questions