Get dict value from key variable inaccessible

Here is my problem, I need to get the dict value from the key. But the key is also var. For example, I had an insignificant role.

In vars / main.yml, I defined vars as shown below:

---
location:   "USA"
source:     {
             "China":  "/net/server1/patha",
             "USA":  "/net/server2/pathb",
             "Japan": "/net/server3/pathc"
            }

So, in my tasks: tasks / main.yml . How to get "/ net / server2 / pathb" using vars. I tried below in tasks, it did not work.

-shell: "perl run.perl {{ source.location }}/script.pl"

-shell: "perl run.perl {{ source.{{ location }} }}/script.pl"

This may be a simple question. But I searched for a lot of messages for a long time and still can not get the correct answer. So please help and thank you very much.

+4
source share
1 answer

The answer {{ source[location] }}.

+9
source

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


All Articles