git - 使用 puppet 使 git 命令行变得丰富多彩
问题描述
我正在尝试使用 puppet 使 git 命令行变得丰富多彩并出现错误。我错过了什么?
exec { 'make-git-color':
command => '/usr/bin/git config --global color.ui auto',
logoutput => 'on_failure',
user => 'vagrant',
timeout => 1200,
require => Package['git']
}
错误是:
/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]
直接运行的命令可以正常工作。/usr/bin/git config --global color.ui auto
但我需要通过木偶来做到这一点。
解决方案
如错误消息所述,未设置 $HOME。您需要将代码更改为这样的内容,以设置缺少的环境变量:
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']
}
这会起作用(我测试过)。将环境变量传递给 exec 的文档在这里。
请注意,我还删除了超时,这不是必需的。
如果您还需要确保幂等性,请根据以下评论将其更改为:
exec { 'make-git-color':
command => 'git config --global color.ui auto',
unless => 'git config --list --global | grep -q color.ui=auto',
path => '/usr/bin',
logoutput => 'on_failure',
user => 'vagrant',
environment => 'HOME=/home/vagrant',
require => Package['git']
}
推荐阅读
- wordpress - 将站点迁移到/从另一台服务器时如何更改 Wordpress 站点 URL?
- angular - 如何在角度 6 中使用 @Output 来发出对象数组?
- vba - 读取 Outlook HTML 正文时出错
- oracle - Oracle Apex IR 无法显示 clob
- javascript - 在方法 split 返回的数组末尾获取一个空字符串
- node.js - 无法使用 Nodejs 网络模块向 GPS 设备 FM1125 发送确认
- model-view-controller - 此页面包含非安全上下文中的密码或信用卡输入
- oracle - oracle序列nextval和currval混淆
- security - 当我有两个 CSP(内容安全策略)策略 - 标头和元时会发生什么?
- java - Java httpServletRequest 转换成数组