当 puppet exec 作为用户时,如何为该用户设置环境?

lee*_*777 7 puppet

我注意到当我使用useron 选项时exec,它不采用指定用户的环境。

$ sudo -i puppet apply -e "exec { '/usr/bin/env': logoutput => true, user => nobody}" 
notice: /Stage[main]//Exec[/usr/bin/env]/returns: SHELL=/bin/bash
notice: /Stage[main]//Exec[/usr/bin/env]/returns: USER=root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: USERNAME=root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
notice: /Stage[main]//Exec[/usr/bin/env]/returns: MAIL=/var/mail/root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: PWD=/root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: HOME=/root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: LOGNAME=root
notice: /Stage[main]//Exec[/usr/bin/env]/returns: executed successfully
Run Code Online (Sandbox Code Playgroud)

因此,尽管该命令运行为nobodyUSERHOME等不按预期设定。有什么方法可以exec模拟登录shell,以便按预期设置环境?

Dan*_*ral 10

没有办法exec模拟登录shell。您始终可以使用su -(如womble建议的)来生成登录 shell,但如果您只需要由 Puppet控制的环境变量,只需使用参数。environment


wom*_*ble 6

当然,通过运行命令su -而不是在清单中指定用户。