我在模板文件foo.cfg.j2中有以下内容
nameserver dns1 {{ lookup('file','/etc/resolv.conf') | regex_search('\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b') }}:53问题是它从本地/etc/resolv.conf获取值。我想从目标中获取值,我了解到我必须使用slurp,但是第二个“问题”是,我需要在任务中注册一个变量,然后将它传递给模板文件,如下所示:
tasks:
- slurp:
src: /etc/resolv.conf
register: slurpfile模板文件现在如下所示:
nameserver dns1 {{ slurpfile['content'] | b64decode | regex_search('\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b') }}:53虽然这样做有效,但我感到有点不安,因为解决方案被分成两部分:任务完成了一些事情,然后模板文件完成了第二部分。是否有一个远程版本的lookup是一个直接替代?
发布于 2022-09-14 04:38:42
我宁愿远程文件,也不愿吃东西
- fetch:
src: /etc/resolv.conf
dest: "{{ fetched_files }}",声明一个变量。
my_etc_recolv_conf: "{{ fetched_files }}/{{ inventory_hostname }}/etc/resolv.conf",并在模板中使用
nameserver dns1 {{ lookup('file', my_etc_recolv_conf) | ...https://stackoverflow.com/questions/73709975
复制相似问题