Akom's Tech Ruminations

Various tech outbursts - code and solutions to practical problems

DevOps Linux Linux

PowerShell on Linux doesn't find modules when run through Puppet

I'm running PowerShell on Linux for the sake of using PowerCLI. An interesting thing happens: when pwsh is run interactively, in a terminal, the following works fine when PowerCLI is already installed:

pwsh -c 'Get-InstalledModule VMware.PowerCLI'

When puppet runs it - it doesn't find the module:

Get-Package: /opt/microsoft/powershell/7/Modules/PowerShellGet/PSModule.psm1:9445
Line |
9445 |          PackageManagement\Get-Package @PSBoundParameters | Microsoft. …
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | No match was found for the specified search criteria and
     | module names 'VMware.PowerCLI'.

Error: 'pwsh -c "if (-not(Get-InstalledModule VMware.PowerCLI)) { Exit 1 }"' returned 1 instead of one of [0]

After some experimentation, I narrowed it down to a single environment variable missing when puppet executes the command: HOME. Set HOME, and powershell will find modules. That gets us the following recipe:

  $my_user = 'some_user'

  exec { 'Install PowerCLI':
    path    => ['/bin', '/usr/bin'],
    command => 'pwsh -c \'Install-Module -Force:$true -Name VMware.PowerCLI\'',
    unless  => 'pwsh -c \'if (-not(Get-InstalledModule VMware.PowerCLI -ErrorAction silentlycontinue)) { Exit 1 }\'',
    user    => $my_user,
    environment => [ "HOME=/home/${my_user}"]

DevOps Java Java

Gradle Toolchains Support - different JVMs for compile and test»
I'm testing a product that needs to be compiled with JDK 8 but tested (sometimes) on JDK 11. This is now possible to do with maven surefire (although that took some effort). With gradle, I was doing it as follows, which is terrible, even if the path comes from configuration: // The old way: test {     executable = '/some/hardcoded/path/to/java' }   ...

DevOps Linux Linux

Puppet recipe for setting up autossh via systemd»
I've always set up autossh in /etc/rc.local , but with CentOS 8 that doesn't work well (things start too early, etc). Luckily, there is a nicer way using systemd templates. Essentially, all you have to do is create one symlink and one config file per instance of autossh. Example: Make a config file /etc/autossh/mything.conf: OPTIONS=-N -M 20000 ...


Using puppet to set Windows Computer Description»
My company's security department decided to assign Antivirus exclusion policies based on the value of the windows computer description. That means that I need to set computer descriptions ( net config server /srvcomment:"new description" ) to the same value on a whole bunch of windows machines. Doing that by hand is unappealing, and I already have puppet, so here is a simple solution: ...

Low Tech Hacks Low Tech Hacks

Replacing Dishwasher Circulation Pump Bearings without buying a whole new unit»
I have a DW80j3020us/AA Samsung dishwasher. It has been producing a loud noise for some time, and the noise kept getting worse. It was a matter of time before it either seized or melted the motor. The reason I know that the problem is with the circulation pump is that the noise is only audible while it's washing (circulating), not while draining or filling. Clearly the problem could be ...


Android doing Optimizing app 1 of 1 on every boot»
The message appears for a good 15 minutes every time my phone boots up. I followed the usual suggestions (wipe cache partition), and that didn't help Figuring out what app is causing this issue is the hard part. I did it with logcat (I happened to have the Android Studio installed, so logcat is a tab, and it displays the log automatically as the plugged-in phone is booting). You ...


Disabling Windows Recycle Bin with Puppet on all versions of Windows»
And when I say "All versions of Windows" I mean that I tested it on Server 2008, 2012 and 2016. This was oddly hard to figure out, and most tutorials either apply to only one version of windows or to outdated tools. The best way to do this that I found was using Local Group Policy. Now, how to automate this? The puppet local group policy module didn't work at all when I tried it ...


Jenkins Pipeline: parallel and waitUntil, waiting until the other branch finishes»
Let's say that for the sake of speed, you are running two slow things in parallel: parallel one: {     node {         sh "sleep 15"     } } , two: {     node {         //slow part:         sh "sleep 10"         ...

Code and Hacks Code and Hacks

Customizing Windows 7 keyboard and mouse to act like Linux»
After using only Linux for nearly 20 years, I'm being forced to use a Windows machine for work. To make matters worse, I'm really (really) used to Enlightenment shortcuts, yet I use XFCE (Xubuntu). So, I'd like to have a seamless experience if I can help it. This is a log of my experimentation. Note that I am not talking about a skin - I don't care that much about the looks, and ...

Linux Linux

OCR on a large PDF using tesseract and pdftk»
This turned out to be harder than I thought. I found a large (50MB) PDF with about 50 pages, and none of the tesseract GUI's seemed to be able to handle it without crashing. The solution is to convert the PDF to TIFF so that command-line tesseract could handle it directly, but now ImageMagick couldn't handle that conversion as it was running out of memory (even with the limit settings). ...

DevOps Java Java Linux Linux

Running Jenkins Swarm client as a service via Upstart»
This turned out to be fairly simple, with only one gotcha: do not follow the how-to's out there that tell you to use expect fork . The process doesn't technically fork. When I had that setting enabled, upstart commands would hang under very specific but repeatable conditions (if the process was killed externally). So, here is my upstart conf file:

DevOps Linux Linux

Docker: Automatically remove containers that have been running too long»
Why Because my Jenkins setup sometimes starts containers and forgets about them. Either it thinks it failed to start one, or the container itself has trouble starting. Either way, I'm left with containers that are running, trying to connect to Jenkins in vain, forever. The proper way to fix this is probably to have the containers timeout at some point, but that mechanism is broken . ...

Automotive Automotive Hardware Hacks Hardware Hacks

Odometer Reprogramming - Nissan Sentra»
Disclaimer : It is perfectly legal to program an odometer to represent the correct mileage for the car. Problem: The car is a 2006 Nissan Sentra 1.8S . The instrument cluster is faulty and flips overdrive on and off at random. I ruled out the rest (switch, TCM). Thus, the cheapest option is to swap in another cluster , but that means that my mileage will be wrong . The ...