Ansible - 访问本地环境变量 [英] Ansible - accessing local environment variables
问题描述
我想知道 Ansible 有没有办法访问本地环境变量.
文档引用了目标机器上的访问变量:
{{ lookup('env', 'SOMEVAR') }}
有没有办法访问源机器上的环境变量?
我有一个在 osx 上运行的 Linux 虚拟机,对我来说:
lookup('env', 'HOME')
返回/Users/Gonzalo"(来自 osx 的 HOME
变量),而 ansible_env.HOME
返回/root"(虚拟机中的 HOME
变量).
值得一提的是,如果变量不存在,ansible_env.VAR
会失败,而 lookup('env', 'VAR')
不会失败.>
I wonder if there is a way for Ansible to access local environment variables.
The documentation references accessing variable on the target machine:
{{ lookup('env', 'SOMEVAR') }}
Is there a way to access environment variables on the source machine?
I have a Linux vm running on osx, and for me:
lookup('env', 'HOME')
returns "/Users/Gonzalo" (the HOME
variable from osx), while ansible_env.HOME
returns "/root" (the HOME
variable from the vm).
Worth to mention, that ansible_env.VAR
fails if the variable does not exists, while lookup('env', 'VAR')
does not fail.
这篇关于Ansible - 访问本地环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!