Search code examples
windowsgitpuppetchocolatey

How do I set Windows environment paths in current Puppet session?


I'm trying to install git and use it in the same puppet script

package { 'git':
  ensure => latest,
  provider => 'chocolatey',
}
vcsrepo { 'C:/':
  provider => git,
  source => 'github etc...',
}

However, I'm getting:

Provider git is not functional on this host

The correct path is included in Environment Variables which leads me to believe that the error is just because the environment variables aren't updated.

The error disappears if I use refreshenv or set "PATH=%PATH%;C:\Program Files\Git\cmd" on the command line or if I restart the command prompt, but is there a way to update them in the same puppet script without manual intervention?

I've tried adding the following to the .pp file (one at a time, of course):

#1
windows_env { 'PATH=C:\Program Files\Git\cmd': }

#2 (I've also tried different variations of quotes)
exec { 'temporary env var':
  path => 'C:/Windows/System32',
  command => 'cmd.exe /c "set \"PATH=$PATH%;C:\\Program Files\\Git\\cmd\""',
}

#3
exec { 'C:/ProgramData/chocolatey/bin/refreshEnv.cmd': }

I guess you could say my question's an extension of Puppet agent: provider git is not functional on this host.


Solution

  • I found a workaround that allows the puppet script to run fully.

    Running set "PATH=%PATH%;C:\Program Files\Git\cmd" in the command line before puppet apply file.pp sets git's future location as an environment variable just for the current command prompt (set, not setx). This way, when another command prompt is opened, the one-time path is gone, but the same path is added from the actual installation of git.