I tried to run a chef recipe on Ubuntu 19.10 that works as expected on Ubuntu 18.04.3. On both Ubuntu versions I installed chef 15.4.45-1 using the package provided on this website.
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
I am using this command to start the chef client: sudo chef-client -z -o "recipe[my-cookbook::my-recipe]"
Output:
* 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
Obviously chef executed the not_if
guard as the root user and not the provided user myusername
.
Am I missing something?
Chef did execute the not_if
clause as your myusername
. However, when doing so, the $HOME
environment variable wasn't updated to point to this user's HOME but remained as /root
.
Thus, git tried to access the files in root's HOME which failed because myusername
has no permission to access files there.
To fix this, you can pass an explicit HOME environment variable:
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
See https://docs.chef.io/resource_common.html#arguments for details about valid arguments.