擅长:python、mysql、java
<p>取决于环境变量的范围:</p>
<p>如果是针对单个用户的,那么导出到用户的local.bash_配置文件就可以了,例如</p>
<pre><code>JAVA_HOME:
# File.append searches the file for your text before it appends so it won't append multiple times
file.append:
- name: /root/.bash_profile
- text: export JAVA_HOME={{ pillar['java_home'] }}
</code></pre>
<p>在使用上述变量之前,您可能需要注销该用户。</p>
<p>另一方面,如果您想全局导出该变量。您可能想使用/etc/profile.d</p>
<pre><code>JAVA_HOME:
file.append:
- name: /etc/profile.d/myglobalenvvariables.sh
- text: export JAVA_HOME={{ pillar['java_home'] }}
</code></pre>
<p>尽管我建议在创建新脚本时使用file.managed。当然,您仍然需要将所有用户注销,以便传播变量。</p>