使用Ansible检索目标节点的env变量 [英] Retrieve env variable of target node using ansible
问题描述
我正在尝试使用ansible获取目标节点的env variale JAVA_HOME值.
I am trying to get env variale JAVA_HOME value of a target node using ansible.
- name: Copy JAVA_HOME location to variable
command: bash -c "echo $JAVA_HOME"
sudo: yes
register: java_loc
当我使用java_loc.stdout值在另一个任务中时,它显示空白值.我如何获取该env变量并将其用于其他任务?
When i use, java_loc.stdout value in another task, it is showing blank value. How can i get that env variable and use it in another task?
我需要将文件复制到JAVA_HOME中存在的JAVA目录中.
I need to copy files to JAVA dir which is present in JAVA_HOME.
推荐答案
使用非登录外壳通过SSH进行的有效登录.可能是您的问题是您在$ HOME/.bash_profile或其他需要登录shell的文件上定义了环境变量,因此您需要在"/bin"中添加" -l </strong>"标志./bash ":
Ansible logins via SSH using non-login shell. Probably your problem is that you defined the environment variable on $HOME/.bash_profile or some other file that requires login shell, so you need to add the "-l" flag to "/bin/bash":
---
- name: Copy JAVA_HOME location to variable
command: /bin/bash -l -c "echo $JAVA_HOME"
sudo: no
register: java_loc
- name: show debug
debug: var=java_loc
请尝试一下,让我知道,
Please, give it a try and let me know,
这篇关于使用Ansible检索目标节点的env变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!