如何在厨师中运行 bash 脚本文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27637589/
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
How to run a bash script file in chef?
提问by jmvbxx
I wrote a short bash script and stored it in files/default/bash.sh
.
我写了一个简短的 bash 脚本并将其存储在files/default/bash.sh
.
How do I link it to get it to run in my main default recipe? It needs to run as sudo because I'm on an ubuntu system.
如何链接它以使其在我的主要默认配方中运行?它需要以 sudo 身份运行,因为我在 ubuntu 系统上。
回答by jmvbxx
回答by coderanger
You can also include the script directly in your recipe if it isn't too long via the bash
resource. By default any program run by Chef uses the same user as Chef is running as, which is usually root already. You can use the user
parameter to things like execute
and bash
to switch to a different user or just explicitly state that it should be root to make things self-documenting a tad.
如果脚本不是太长,您还可以通过bash
resource直接将脚本包含在您的配方中。默认情况下,Chef 运行的任何程序都使用与运行 Chef 相同的用户,该用户通常已经是 root。您可以将user
参数用于诸如execute
和bash
切换到其他用户之类的事情,或者只是明确声明它应该是 root 以使事情自我记录一点。