How do I get dict key from ansible playbook variable?

HOW TO -️ October 18, 2021

Following is the desire output:

ERROR Rendering Code Block

The idea is to pass domain name ie in playbook and playbook will lookup its A record then check it against the predefined variable. If ip is found in variable then it will display the corresponding key.

Here is my ansible-playbook role:


ERROR Rendering Code Block


ERROR Rendering Code Block


What is the problem? Apart from the fact that hosts is a reserved variable name. oh, I want to pass domain name then playbook will resolve its ip and show in which server that domain belongs to. Why do you want this? it is just a small portion of a big playbook. You can think it as a small project or also think as I am practicing.