大网数据广告活动
服务器运维问答

Set environment variable in Puppet

· 52CE 我爱测

I'd like to set an environment variable on my Linux systems managed by Puppet to contain the name of the currently running branch, puppet's $environment . It needs to be a system level variable from anywhere and any user the syst…

问题原文

原帖链接 · Tim Brigham · CC BY-SA 3.0

I'd like to set an environment variable on my Linux systems managed by Puppet to contain the name of the currently running branch, puppet's $environment. It needs to be a system level variable from anywhere and any user the system - I'm trying to avoid any kind of file system tomfoolery if at all possible.

Basically I'd like to be able to read this variable in other code and include it in the logs it creates.

Ideally I'm looking for a cross platform answer, but CentOS / RedHat specific would be a great start.

Edit: I'd like to avoid having some random file under /etc/ that I need to read every time I write a line in my log.

I thought about using profile.d shortly after I posted. Problem is a lot of services don't load the profile, and even if I do use a fragment it'd require rereading the profile if I make a change.

已采纳解答

原帖链接 · Daniel Scott · CC BY-SA 3.0

The 'standard' way of doing this is to add a file /etc/profile.d/environment.sh

Containing

export VAR1=value1

As you said, some services (cron) don't start login shells, or don't read the environment, they have to be done in a different way.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-03-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。