I have the following in a template file foo.cfg.j2
:
nameserver dns1 {{ lookup('file','/etc/resolv.conf') | regex_search('\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b') }}:53
The problem is it gets the value from the local /etc/resolv.conf
. I wanted to get the value from the target, I learned that I have to use slurp
, but the second "problem" is that I need to register an variable in the task, and then pass it to the template file, like this:
tasks:
- slurp:
src: /etc/resolv.conf
register: slurpfile
and the template file is now like this:
nameserver dns1 {{ slurpfile['content'] | b64decode | regex_search('\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b') }}:53
While this works, I feel a bit uneasy as the solution is split into two places: the task does something, and then the template file does the second part. Is there a remote version of lookup
that is a direct replacement?