make git command line colorful using puppet

make git command line colorful using puppet



I am trying to make git command line colorful using puppet and getting error. what am i missing?


exec 'make-git-color':
command => '/usr/bin/git config --global color.ui auto',
logoutput => 'on_failure',
user => 'vagrant',
timeout => 1200,
require => Package['git']



Error is:


/Exec[make-git-color]/returns: fatal: $HOME not set
Error: '/usr/bin/git config --global color.ui auto' returned 128 instead of one of [0]



command running directly works fine. /usr/bin/git config --global color.ui auto


/usr/bin/git config --global color.ui auto



But I need to do it via puppet.




3 Answers
3



As the error message says, $HOME is not set. You need to change your code to something like this, to set the missing environment variable:


exec 'make-git-color':
command => '/usr/bin/git config --global color.ui auto',
logoutput => 'on_failure',
user => 'vagrant',
environment => 'HOME=/home/vagrant',
require => Package['git']



That will work (I tested it). Docs for passing environment variables to exec are here.



Notice I also removed the timeout, which wasn't required.



If you need to also ensure idempotence, per the comments below, change it to:


exec 'make-git-color':
command => 'git config --global color.ui auto',
unless => 'git config --list --global






That seems more accurate than my answer. +1

– VonC
Sep 11 '18 at 6:26






Wouldn't that execute the command everytime when puppet agent runs? Wouldn't it be good to add some unless clause there?

– Marcin Pietraszek
Sep 11 '18 at 7:35


unless






@MarcinPietraszek, that's a good point, updated. Note that many users are doing masterless or immutable infrastructure, so idempotence doesn't always matter.

– Alex Harvey
Sep 11 '18 at 8:13






@AlexHarvey I would argue that masterless still needs to be idempotent, even if immutable often does not, but I think the real argument here is that a Vagrant instance is an initial provision. Therefore, although idempotence is often unnecessary here, a vagrant provision could always be executed via the CLI and then it would be a "nice-to-have". Super minor nitpick, but I think grep is in only /bin on older systems by the way (regarding your path attribute).

– Matt Schuchard
Sep 11 '18 at 15:30


vagrant provision


grep


/bin


path



The error message shows that git is complaining about the HOME environment variable not being set. Other answers describe how you can provide a value for this variable, but that's not necessarily the right way to approach this particular problem.


git


HOME



Consider that the fact that git cares about HOME suggests that it is trying set configuration at the per-user level. If that's indeed what you want then fine, but doing it via Puppet seems a bit overkill vs. just running the command directly. On the other hand, if by "--global" you thought you were setting the property at the system-wide level, then you are in for a surprise. git config --global sets "global" configuration in the sense of affecting all of a particular user's repositories (that do not override it). System-wide properties are selected via the --system option:


git


HOME


git config --global


--system


exec grep -q color.ui=auto',



In that case, you should also consider whether it is appropriate to run the command as user 'vagrant', as it's unclear whether that user has the appropriate authority to modify the system-wide configuration.



You should also consider whether you need such a long timeout. I don't quite see the circumstance in which you expect that it takes that long to have reasonable confidence that the command has hung.






These are some good points, and mentioning that this exec resource might not be the best way to approach the problem makes me wonder if a better approach would not be to manage the files at .git/config and/or $HOME/.gitconfig and/or /etc/gitconfig with file resource(s).

– Matt Schuchard
Sep 11 '18 at 15:39


exec


.git/config


$HOME/.gitconfig


/etc/gitconfig


file



I implemented the work around using file.


file '/home/vagrant/.gitconfig':
content => "[color]n ui = auto",
owner => 'vagrant',
group => 'vagrant',
require => Package['git'],



but answer which Alex gave above may be the right one. going to try that now :)



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)