Ansible - 访问本地环境变量 [英] Ansible - accessing local environment variables

查看:48
本文介绍了Ansible - 访问本地环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 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屋!

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