首页 > 解决方案 > 如何通过 Chef 配置 Bundler?

问题描述

我们使用 Chef 来设置和执行 Bundler。我们之前在and属性设置为的资源中运行bundle install, (捆绑器操作旨在以该用户身份运行)。bashusergrouptarget_user

由于某些选项(即--deployment--path--without)的弃用,我们现在需要通过配置它们bundle config

但是,似乎在使用相同的资源配置时,Bundle 无法按预期工作;我们得到Bundler::SudoNotPermittedError: Bundler requires sudo access to install...,我想这是因为配置文件没有存储在正确的位置,和/或读取。

资源应该如何execute配置?目前,它是:

# Simplified version
bash "Install gems" do
  code <<~EOF
    bundle config --local deployment true &&
    bundle config --local path /path/to/gems_dir &&
    bundle install --gemfile=/path/to/Gemfile
  EOF

  user "target_user"
  group "target_user"
end

标签: rubybashenvironment-variableschef-infraenvironment

解决方案


您将此bash资源作为target_user运行,这就是错误的原因。我认为您在这里有两个选择:

  1. 从资源中删除用户和组,然后它将以 root 身份运行。
  2. 在中的每个捆绑命令之前添加sudocode,并确保target_user是没有密码的 sudoer。

推荐阅读