在 Jinja 模板中使用 Ansible control master 的 IP 地址 [英] Use Ansible control master's IP address in Jinja template

查看:27
本文介绍了在 Jinja 模板中使用 Ansible control master 的 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Ansible 剧本使用的 J2 模板中插入一个 IP 地址.该 IP 地址是不是正在供应的主机的地址,而是完成供应的主机的 IP.到目前为止,我发现的所有内容都涵盖了使用与正在配置的主机相关的变量/事实.换句话说:当执行 ansible -m setup 127.0.0.1 时,我想插入的 IP 是 ['ansible_default_ipv4']['address'] 中的 IP.

I would like to insert an IP address in to a J2 template which is used by an Ansible playbook. That IP adress is not the address of the host which is being provisioned, but the IP of the host from which the provisioning is done. Everything I have found so far covers using variables/facts related to the hosts being provisioned. In other words: the IP I’d like to insert is the one in ['ansible_default_ipv4']['address'] when executing ansible -m setup 127.0.0.1.

我认为我可以使用本地剧本来编写一个动态生成的包含 IP 的模板文件,但我希望这可能是Ansible 方式".

I think that I could use a local playbook to write a dynamically generated template file containing the IP, but I was hoping that this might be possible "the Ansible way".

推荐答案

就用这个:

{{ ansible_env["SSH_CLIENT"].split()[0] }}

这篇关于在 Jinja 模板中使用 Ansible control master 的 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆