Module: PuppetLitmus::Util

Defined in:
lib/puppet_litmus/util.rb

Overview

Helper methods for testing puppet content

Class Method Summary collapse

Class Method Details

.interpolate_powershell(command) ⇒ String

Ensure that a passed command is base 64 encoded and passed to PowerShell; this obviates the need to carefully interpolate strings for passing to ruby which will then be passed to PowerShell/CMD which will then be executed. This also ensures that a single PowerShell command may be specified for Windows targets leveraging PowerShell as bolt run_shell will use PowerShell against a remote target but CMD against a localhost target.

Parameters:

  • :command (String)

    A PowerShell script block to be converted to base64

Returns:

  • (String)

    An invocation for PowerShell with the encoded command which may be passed to run_shell



13
14
15
16
# File 'lib/puppet_litmus/util.rb', line 13

def self.interpolate_powershell(command)
  encoded_command = Base64.strict_encode64(command.encode('UTF-16LE'))
  "powershell.exe -NoProfile -EncodedCommand #{encoded_command}"
end