运行.bash_profile出现问题的原因
问题描述:
我想通过ansible导出多个变量。我有这样的任务,我的剧本运行.bash_profile出现问题的原因
- name: Set the MIRA_ROOT and Binding_Address in Profile
lineinfile: dest=/root/.bash_profile insertbefore='^export PATH' line=" {{item.line}}"
with_items:
- { line: 'export JAVA_HOME=/usr/java/jdk{{jdk_version}}' }
- { line: 'export MIRA_ROOT=/opt/data/rg01/mira' }
如何运行.bash_profile中?我写了这个代码的.bash_profile运行,但它不能正常工作
- name: Run the bash_profile
shell: source /root/.bash_profile
答
什么是你的目标是什么?你想永久设置这些变量还是仅仅为了你的演奏?无论如何.bash_profile
可能不是最好的解决方案。
Ansible为每个任务启动一个新的ssh连接。如果你想在一个任务中设置.bash_profile
来设置环境变量,那么在下一个任务中它将不可用。
如果你想永久设置它,你可以把它写到/etc/environment
,lineinfile
模块就像你一样。
如果你只是想设置它的Ansible戏的任务,你可以set it in your playbook:
- hosts: ...
environment:
JAVA_HOME: /usr/java/jdk{{jdk_version}}
MIRA_ROOT: /opt/data/rg01/mira
tasks: ...
roles: ...
我要永久设定的变量,我试图在/ etc /环境,但它不能正常工作请用示例帮助我 – user3345734