代码之家  ›  专栏  ›  技术社区  ›  Developer

使用puppet使git命令行色彩丰富

  •  1
  • Developer  · 技术社区  · 6 年前

    我正在尝试使用木偶使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

    但我需要通过木偶来完成。

    3 回复  |  直到 6 年前
        1
  •  2
  •   Alex Harvey    6 年前

    如错误消息所示,未设置$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的文档有 here .

    注意我也删除了超时,这不是必需的。

    如果您还需要确保等幂,根据下面的注释,将其更改为:

    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']
    }
    
        2
  •  1
  •   John Bollinger    6 年前

    错误消息显示 git 在抱怨 HOME 未设置环境变量。其他答案描述了如何为这个变量提供一个值,但这不一定是处理这个特定问题的正确方法。

    考虑到这个事实 吉特 关心 建议它尝试在每个用户级别设置配置。如果这确实是你想要的,那就好了,但通过木偶做似乎有点过分了。 VS . 直接运行命令。另一方面,如果是“-global”,你认为你是在 全系统范围 水平,然后你会有惊喜。 git config --global 设置“全局”配置,以影响所有 特定用户的 存储库(不会覆盖它)。通过选择系统范围的属性 --system 选项:

    exec { 'make-git-color':
      command => '/usr/bin/git config --system color.ui auto',
      logoutput => 'on_failure',
      user      => 'vagrant',
      timeout   => 1200,
      require   => Package['git'],
      unless    => 'git config --list --system | grep -q color.ui=auto',
    }
    

    在这种情况下,您还应该考虑作为用户“vagrant”运行该命令是否合适,因为不清楚该用户是否具有修改系统范围配置的适当权限。

    您还应该考虑是否需要这么长的超时时间。我不太明白你所期望的那种情况,在这种情况下,你需要那么长的时间才能有合理的信心相信命令已经挂起了。

        3
  •  1
  •   Developer    6 年前

    我使用文件实现了这项工作。

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

    但亚历克斯上面给出的答案可能是正确的。现在就试试看:)