Using A Proxy With Puppet’s pe_gem Module

So, I’ve defined a puppet_master role and profile to help manage some gems and other stuff that is needed there. Because the gems need to be installed in Puppet’s ruby environment as opposed to the system’s ruby environment, I installed the pe_gem module. It’s a simple module that adds a new provider, pe_gem, for the package type that replaces the gem command with the one in Puppet’s ruby.

In one of my environments, all of the nodes must access the Internet via a proxy. And that started this wacky adventure, complete with trips down multiple rabbit holes.

My first attempt was to set the environment variables. Works great from the command line, but when the agent runs, it fails. So, moving on, the documentation indicates that I could add the proxy command line arg via the package type’s install_options resource.

Yeah, not so much. The package never actually got that resource due to a bug in the pe_gem module. It turns out that it’s missing the feature definition. I fixed that locally, tested it, and then forked the module, checked in my fix, and created a pull request on Github. That sorta worked. It’ll install the gems, but the list command that Puppet does to check the version still fails because the install_options resource isn’t used for ‘gem list’ commands. At that point I set the ensure resources to ‘present’ and gave up for the night.

This morning I tried using a gemrc file to specify the proxy. Putting http_proxy in ~/.gemrc doesn’t work because Puppet unsets $HOME. Putting it in /etc/gemrc kind of works, but gem tries to do the list command without a proxy first. Not ideal, but I can live with that if I have to. Not satisfied with that though, I start crawling through Puppet’s ruby code and find the answer. Bingo! It’s not /etc, it’s /opt/puppet/etc. So I moved the gemrc over to /opt/puppet/etc, which appears to have solved everything.