bash Puppet exec 命令在 shell 中运行,但不是通过 puppet 运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11173323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Puppet exec command runs in shell, but not via puppet
提问by jeremiahs
I'm trying to use vagrant to set up a dev environment that automatically clones two repositories if they haven't already been cloned.
我正在尝试使用 vagrant 设置一个开发环境,如果两个存储库尚未被克隆,它会自动克隆两个存储库。
I wrote a simple script to clone the repos, after failing in many, many ways to get puppet to run the git command directly. For some reason I thought this method would be foolproof, but it turns out I'm a better fool than I thought.
我写了一个简单的脚本来克隆 repos,在很多很多方法都失败后让 puppet 直接运行 git 命令。出于某种原因,我认为这种方法是万无一失的,但结果证明我比我想象的更傻。
exec {"load-repos":
command =>"/bin/bash /vagrant/manifests/modules/scripts/clone_repos.sh",
require => Package["git-core"],
}
Here's the script:
这是脚本:
#!/bin/bash
if [ ! -d /vagrant/repo-one-dest ]; then
git clone [email protected]:/repo-one.git /vagrant/repo-one-dest
fi
if [ ! -d /vagrant/repo-two-dest ]; then
git clone [email protected]:/repo-two.git /vagrant/repo-two-dest
fi
exit
The private keys are set up properly. When I log into the vm and manually run bash clone_repos.sh, everything works. No matter how many times I reload vagrant and let puppet do its thing, the repos are never loaded via the exec. What am I missing?
私钥设置正确。当我登录虚拟机并手动运行时bash clone_repos.sh,一切正常。无论我重新加载 vagrant 多少次并让 puppet 做它的事情,repos 都不会通过 exec 加载。我错过了什么?
采纳答案by Mitchell
This is probably because when you vagrant sshyou're usually logging in as the vagrantuser (by default, though this can certainly be modified via configuration). The vagrantuser I'm guessing has the keys setup properly.
这可能是因为当您vagrant ssh通常以vagrant用户身份登录时(默认情况下,虽然这当然可以通过配置进行修改)。vagrant我猜的用户已正确设置了密钥。
When Vagrant runs your provisioner (Puppet, in this case), however, it does a sudo, so it runs as the root user.
但是,当 Vagrant 运行您的配置器(在本例中为 Puppet)时,它会执行sudo,因此它以 root 用户身份运行。
The way I generally recommend setting up keys to do the deploy is to put the keys somewhere, and then use a GIT_SSHwrapper to properly clone it, or to use SSH agents.
我通常建议设置密钥以进行部署的方法是将密钥放在某处,然后使用GIT_SSH包装器正确克隆它,或者使用 SSH 代理。

