Module: Beaker::DSL::Wrappers

Included in:
Beaker::DSL, PSWindows::Exec
Defined in:
lib/beaker/dsl/wrappers.rb

Overview

These are wrappers to equivalent Command objects so that command line actions are executed within an appropriate and configurable environment.

I find most of these adapters of suspicious value and have deprecated many of them.

Instance Method Summary collapse

Instance Method Details

#cfacter(*args) ⇒ Object

This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.



26
27
28
29
30
31
# File 'lib/beaker/dsl/wrappers.rb', line 26

def cfacter(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  options['ENV'] ||= {}
  options[:cmdexe] = true
  Command.new('cfacter', args, options )
end

#facter(*args) ⇒ Object

This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.



15
16
17
18
19
20
# File 'lib/beaker/dsl/wrappers.rb', line 15

def facter(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  options['ENV'] ||= {}
  options[:cmdexe] = true
  Command.new('facter', args, options )
end

#hiera(*args) ⇒ Object

This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.



37
38
39
40
41
42
# File 'lib/beaker/dsl/wrappers.rb', line 37

def hiera(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  options['ENV'] ||= {}
  options[:cmdexe] = true
  Command.new('hiera', args, options )
end

#powershell(command, args = {}) ⇒ Command

Returns a Command object for executing powershell commands on a host

Examples:

Setting the contents of a file

powershell("Set-Content -path 'fu.txt' -value 'fu'")

Using an alternative execution policy

powershell("Set-Content -path 'fu.txt' -value 'fu'", {'ExecutionPolicy' => 'Unrestricted'})

Parameters:

  • command (String)

    The powershell command to execute

  • args (Hash) (defaults to: {})

    The commandline paramaeters to be passed to powershell

Returns:



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/beaker/dsl/wrappers.rb', line 119

def powershell(command, args={})
  ps_opts = {
    'ExecutionPolicy' => 'Bypass',
    'InputFormat'     => 'None',
    'NoLogo'          => '',
    'NoProfile'       => '',
    'NonInteractive'  => ''
  }
  ps_opts.merge!(args)
  ps_args = []
  ps_opts.each do |k, v|
    if v.eql?('') or v.nil?
      ps_args << "-#{k}"
    else
      ps_args << "-#{k} #{v}"
    end
  end
  ps_args << "-Command #{command}"

  Command.new("powershell.exe", ps_args)
end

#puppet(*args) ⇒ Object

This is hairy and because of legacy code it will take a bit more work to disentangle all of the things that are being passed into this catchall param.



57
58
59
60
61
62
63
64
65
# File 'lib/beaker/dsl/wrappers.rb', line 57

def puppet(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  options['ENV'] ||= {}
  options[:cmdexe] = true
  # we assume that an invocation with `puppet()` will have it's first argument
  # a face or sub command
  cmd = "puppet #{args.shift}"
  Command.new( cmd, args, options )
end