get dict value from variable key in ansible


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

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

So in my tasks: tasks/main.yml. How do get “/net/server2/pathb” using the vars. I tried below in tasks, all did not work.

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

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

This may be a simple question. But I searched many posts for a long time and still cannot get a right answer. So please help and many thanks.


The answer is {{ source[location] }}.

Leave a Reply