Class: Chef::Resource::Powershell

Inherits:
Script
  • Object
show all
Defined in:
lib/chef/providers/windows/powershell_resource.rb

Overview

Powershell chef resource. Allows defining recipes which wrap Powershell v1.0 scripts.

Example

powershell “My Powershell Script” do

source "write-output \"Running powershell v1.0 script\""

end

Instance Method Summary collapse

Constructor Details

#initialize(name, run_context = nil) ⇒ Powershell

Initialize Powershell resource with default values

Parameters

name(String)

Nickname of Powershell

collection(Array)

Collection of included recipes

node(Chef::Node)

Node where resource will be used



45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/providers/windows/powershell_resource.rb', line 45

def initialize(name, run_context=nil)
  super(name, run_context)
  @resource_name = :powershell
  @interpreter = "powershell"
  @parameters = {}
  @source = nil
  @source_path = nil
  @action = :run
  @allowed_actions.push(:run)
end

Instance Method Details

#nickname(arg = nil) ⇒ Object

(String) Powershell nickname



57
58
59
60
61
62
63
# File 'lib/chef/providers/windows/powershell_resource.rb', line 57

def nickname(arg=nil)
  set_or_return(
    :nickname,
    arg,
    :kind_of => [ String ]
  )
end

#parameters(arg = nil) ⇒ Object

(Hash) Powershell parameters values keyed by names



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/chef/providers/windows/powershell_resource.rb', line 84

def parameters(arg=nil)
  return environment if arg.nil?

  # FIX: support Windows alpha demo-style parameters for now. document
  # that they are deprecated and to use a simple hash. this method of
  # parameter passing may be deprecated altogether in future.
  if arg.kind_of?(Chef::Node::Attribute)
    arg = arg.attribute
  end

  # parameters is really a duplication of the environment hash from
  # the ExecuteResource, so merge the two hashes, if necessary. it seems
  # valid to continue to distinguish symantically between parameters and
  # environment because the user does not necessarily need to know that
  # they are implemented to be the same hash.
  env = environment
  if env.nil?
    env = arg
  else
    env.merge!(arg)
  end
  environment(env)
  @parameters = @environment
end

#source(arg = nil) ⇒ Object

(String) text of Powershell source code if inline



66
67
68
69
70
71
72
# File 'lib/chef/providers/windows/powershell_resource.rb', line 66

def source(arg=nil)
  set_or_return(
    :source,
    arg,
    :kind_of => [ String ]
  )
end

#source_path(arg = nil) ⇒ Object

(String) local path for external Powershell source file if not inline



75
76
77
78
79
80
81
# File 'lib/chef/providers/windows/powershell_resource.rb', line 75

def source_path(arg=nil)
  set_or_return(
    :source_path,
    arg,
    :kind_of => [ String ]
  )
end