lookup module didn't replace variable value that is given as file name

Hi,

I have problem with the lookup module, I am given the file name as a variable, it takes it but didn’t replace the variable with it’s value. For example:

pub_subnet: “{{ lookup(‘file’, ‘./vars/{{ vpc_name }}_public_subnet.yml’) }}”

When I run the playbook, it should replace it with the variable name: tendo_public_subnet.yml

But it is giving me an error of:

TASK: [VPC | set the facts] ***************************************************
fatal: [localhost] => could not locate file in lookup: ./vars/{{ vpc_name }}_public_subnet.yml

FATAL: all hosts have already failed – aborting

Can somebody point me that where I am making a mistake.

Thanks

Too many moustaches!

{{ }} are not stackable, try the following:

pub_subnet: "{{ lookup('file', './vars/' + vpc_name + ' _public_subnet.yml') }}"

Hi Brain,

Bundles of Thanks, it’s work for me.

If you don’t mind, can you please also give me your valuable comment here:
https://groups.google.com/forum/#!topic/ansible-project/Zyb1X4clSWU

Thanks