Is there a way to resolve an arbitrary string as the host name in the Ansible file group_varsor in the Jinja2 template used by Ansible? Let's say I want to define a variable in global_vars/allwhich will contain one of several IP addresses allowed www.google.com. In this example, I used www.google.comas an example a string that can be resolved to multiple IP addresses, and yet I cannot use Ansible hostvarsfor the address, because I cannot ssh into it.
I tried connecting to Pythonic socket.gethostbyname()but could not get the syntax correctly. At best, my variable became literal "socket.gethostbyname (" my-host-1 ")".
I know that I can go back to the shell script and use the tools available in the shell, but I would like to see if there is an elegant way to do this in Ansible.
The more details of the question, the more I must fill out the Postgres HBA configuration file with the IP addresses of the allowed hosts. I cannot use my hostnames because the target deployment does not have the reverse DNS required for HBA based on the hostname.
I really want Postgres to resolve the names in the configuration file and map it to the client IP address instead of looking back at the client IP address, and then match the hostname strings. But this is too much to expect and wait too long. I need a workaround for now, and I would like to stay in Ansible for this, without having to unload it into an external script.
, !