ruby - Chef shell 脚本未运行

标签 ruby shell sh chef-infra

我在 Scalarium 上使用 Chef下载代理并在其上运行各种命令。我正在尝试的是在配方中编写一个 shell 脚本来执行此操作。

file "/etc/profile.d/blah.sh" do
  content <<-EOH
sudo -sH
<Retrieve file and run some commands>
  EOH
end

当我在 Scalarium 中运行配方时,没有发生错误,但命令也没有运行。命令本身没有错误,因为我已经在我的计算机上运行了它们。

配方肯定被阅读了,因为 Chef 日志包含 blah.localdomain 上的处理文件[/etc/profile.d/blah.sh]

我以前从未使用过 Chef,我是否需要做其他事情来告诉它执行 shell 脚本?

最佳答案

也许你想要这样的东西:

file "/etc/profile.d/blah.sh" do
  mode 0500
  content <<-EOH
sudo -sH
<Retrieve file and run some commands>
  EOH
end

execute "/etc/profile.d/blah.sh"

或者,您可以将文件检索和命令运行直接放入您的 Chef Recipe 中:

remote_file "/path/to/where/the/file/should/be/saved" do
  source "https://example.com/path/to/where/the/file/comes/from"
end

execute "first command"
execute "second command"

关于ruby - Chef shell 脚本未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7348541/

相关文章:

ruby - 如何将散列保存到 CSV 中

ruby-on-rails - 将 Rails DateTime 四舍五入到最接近的 15 分钟间隔

从 Firefox Web 扩展执行 Javascript shell 命令

regex - 组合多个 sed 命令

linux - 进程未显示在 "ps -e"输出中

ruby-on-rails - Rails Postgres - 日期时间值不会保存到日期时间列中

ruby-on-rails - 关注包含的测试 belongs_to

linux - 找不到相关命令

vim - tmux:如何在光标下打开文件

linux - 如何在unix中显示文件第n行的所有行