Chef infra Ubuntu19.10上的厨师:坏食谱

Chef infra Ubuntu19.10上的厨师:坏食谱,chef-infra,chef-recipe,Chef Infra,Chef Recipe,我试着在Ubuntu19.10上运行一个厨师食谱,它在Ubuntu18.04.3上的效果与预期的一样。在两个Ubuntu版本上,我都使用上提供的软件包安装了chef 15.4.45-1 我正在使用此命令启动厨师客户端:sudo chef client-z-o“recipe[my cookbook::my recipe]” 输出: * execute[Git LFS: Install user configuration] action run ===================

我试着在Ubuntu19.10上运行一个厨师食谱,它在Ubuntu18.04.3上的效果与预期的一样。在两个Ubuntu版本上,我都使用上提供的软件包安装了chef 15.4.45-1

我正在使用此命令启动厨师客户端:
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将
not\u if
guard作为根用户而不是提供的用户
myusername
执行


我遗漏了什么吗?

厨师确实执行了
not\u if
子句作为您的
myusername
。但是,执行此操作时,
$HOME
环境变量未更新为指向此用户的家,而是保持为
/root

因此,git试图访问root主页中的文件,但失败了,因为
myusername
无权访问那里的文件

要解决此问题,可以传递一个显式的主环境变量:

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

有关有效参数的详细信息,请参阅。

对于您建议的更改,命令将按预期执行,但我不喜欢更改几百个配方以手动设置环境变量。我从Ubuntu14.04开始使用这个配方,它总是在没有明确设置环境变量的情况下工作。
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