【问题标题】:Chef on Ubuntu 19.10: broken recipeUbuntu 19.10 上的厨师:错误的食谱
【发布时间】:2019-10-30 01:51:39
【问题描述】:

我尝试在 Ubuntu 19.10 上运行一个在 Ubuntu 18.04.3 上按预期运行的厨师食谱。在两个 Ubuntu 版本上,我使用 this website 上提供的软件包安装了 chef 15.4.45-1。

execute 'Git LFS: Install user configuration' do
  command 'git lfs install'

  user 'myusername'

  not_if 'git config --global filter.lfs.required | grep "true"', :user => 'myusername'
end

我正在使用这个命令来启动 Chef 客户端:sudo chef-client -z -o "recipe[my-cookbook::my-recipe]"

输出:

  * execute[Git LFS: Install user configuration] action run

    ================================================================================
    Error executing action `run` on resource 'execute[Git LFS: Install user configuration]'
    ================================================================================

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '2'
    ---- Begin output of git lfs install ----
    STDOUT: WARNING: Error running /usr/lib/git-core/git 'config' '--global' '--replace-all' 'filter.lfs.required' 'true': 'warning: unable to access '/root/.gitconfig': Permission denied
    warning: unable to access '/root/.config/git/config': Permission denied
    error: could not lock config file /root/.gitconfig: Permission denied' 'exit status 255'
    Run `git lfs install --force` to reset git config.
    STDERR: 
    ---- End output of git lfs install ----
    Ran git lfs install returned 2

显然 chef 以 root 用户而不是提供的用户 myusername 身份执行了 not_if 守卫。

我错过了什么吗?

【问题讨论】:

    标签: chef-infra chef-recipe


    【解决方案1】:

    Chef 确实将not_if 子句作为您的myusername 执行。但是,这样做时,$HOME 环境变量并未更新为指向该用户的 HOME,而是保持为 /root

    因此,git 尝试访问 root 的 HOME 中的文件失败了,因为 myusername 没有访问那里的文件的权限。

    要解决此问题,您可以传递显式 HOME 环境变量:

    execute 'Git LFS: Install user configuration' do
      command 'git lfs install'
    
      user 'myusername'
    
      not_if 'git config --global filter.lfs.required | grep "true"', :user => 'myusername', :environment => { 'HOME' => '/home/myusername' }
    end
    

    有关有效参数的详细信息,请参阅https://docs.chef.io/resource_common.html#arguments

    【讨论】:

    • 随着您提出的更改,命令按预期执行,但我不喜欢更改数百个配方以手动设置环境变量的想法。我从 Ubuntu 14.04 开始使用这个配方,它总是在没有明确设置环境变量的情况下工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多