0

I have a variable client: client1 and I want to use it to fetch multiple facts into a template like below.

"{{ hostvars[{{ client }}][ansible_default_ipv4][address] }}"

"{{ hostvars[{{ client }}][ansible_hostname] }}"

"{{ hostvars[{{ client }}][ansible_fqdn] }}"

I have tried removing the braces, using a dictionary[key] in place of client but couldn't figure out. What is the right usage here?

1 Answer 1

2

The right answer is: "{{ hostvars[client]['ansible_default_ipv4']['address'] }}"

Sign up to request clarification or add additional context in comments.

1 Comment

how can this be done. region: 1 dev1_ips: 1,2 {{ dev[region]_ips }} . This is not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.