Class: Bolt::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/target.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, inventory = nil) ⇒ Target

rubocop:enable Lint/UnusedMethodArgument



40
41
42
43
# File 'lib/bolt/target.rb', line 40

def initialize(name, inventory = nil)
  @name = name
  @inventory = inventory
end

Instance Attribute Details

#inventoryObject

Returns the value of attribute inventory.



8
9
10
# File 'lib/bolt/target.rb', line 8

def inventory
  @inventory
end

#nameObject (readonly)

Returns the value of attribute name.



130
131
132
# File 'lib/bolt/target.rb', line 130

def name
  @name
end

Class Method Details

.from_asserted_args(uri = nil, name = nil, safe_name = nil, target_alias = nil, config = nil, facts = nil, vars = nil, features = nil, plugin_hooks = nil, resources = nil) ⇒ Object

TODO: Disallow any positional argument other than URI. Target.new from a plan with just a uri. Puppet requires the arguments to this method to match (by name) the attributes defined on the datatype. rubocop:disable Lint/UnusedMethodArgument



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bolt/target.rb', line 26

def self.from_asserted_args(uri = nil,
                            name = nil,
                            safe_name = nil,
                            target_alias = nil,
                            config = nil,
                            facts = nil,
                            vars = nil,
                            features = nil,
                            plugin_hooks = nil,
                            resources = nil)
  from_asserted_hash('uri' => uri)
end

.from_asserted_hash(hash) ⇒ Object

Target.new from a plan initialized with a hash



17
18
19
20
# File 'lib/bolt/target.rb', line 17

def self.from_asserted_hash(hash)
  inventory = Puppet.lookup(:bolt_inventory)
  from_hash(hash, inventory)
end

.from_hash(hash, inventory) ⇒ Object

Target.new from a data hash



11
12
13
14
# File 'lib/bolt/target.rb', line 11

def self.from_hash(hash, inventory)
  target = inventory.create_target_from_hash(hash)
  new(target.name, inventory)
end

Instance Method Details

#configObject



67
68
69
# File 'lib/bolt/target.rb', line 67

def config
  inventory_target.config
end

#detailObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/bolt/target.rb', line 105

def detail
  {
    'name' => name,
    'uri' => uri,
    'alias' => target_alias,
    'config' => {
      'transport' => transport,
      transport => options.to_h
    },
    'vars' => vars,
    'features' => features,
    'facts' => facts,
    'plugin_hooks' => plugin_hooks,
    'groups' => @inventory.group_names_for(name)
  }
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


169
170
171
# File 'lib/bolt/target.rb', line 169

def eql?(other)
  self.class.equal?(other.class) && @name == other.name
end

#factsObject



59
60
61
# File 'lib/bolt/target.rb', line 59

def facts
  @inventory.facts(self)
end

#feature_setObject

Use feature_set internally to access set



51
52
53
# File 'lib/bolt/target.rb', line 51

def feature_set
  @inventory.features(self)
end

#featuresObject

features returns an array to be compatible with plans



46
47
48
# File 'lib/bolt/target.rb', line 46

def features
  @inventory.features(self).to_a
end

#hashObject



174
175
176
# File 'lib/bolt/target.rb', line 174

def hash
  @name.hash
end

#hostObject



126
127
128
# File 'lib/bolt/target.rb', line 126

def host
  inventory_target.host
end

#inventory_targetObject



122
123
124
# File 'lib/bolt/target.rb', line 122

def inventory_target
  @inventory.targets[@name]
end

#passwordObject



161
162
163
# File 'lib/bolt/target.rb', line 161

def password
  inventory_target.password
end

#plugin_hooksObject



165
166
167
# File 'lib/bolt/target.rb', line 165

def plugin_hooks
  inventory_target.plugin_hooks
end

#portObject



140
141
142
# File 'lib/bolt/target.rb', line 140

def port
  inventory_target.port
end

#protocolObject



153
154
155
# File 'lib/bolt/target.rb', line 153

def protocol
  inventory_target.protocol || inventory_target.transport
end

#remote?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/bolt/target.rb', line 136

def remote?
  protocol == 'remote'
end

#resourcesObject



79
80
81
# File 'lib/bolt/target.rb', line 79

def resources
  inventory_target.resources
end

#safe_nameObject



71
72
73
# File 'lib/bolt/target.rb', line 71

def safe_name
  inventory_target.safe_name
end

#set_local_defaultsObject



83
84
85
# File 'lib/bolt/target.rb', line 83

def set_local_defaults
  inventory_target.set_local_defaults
end

#set_resource(resource) ⇒ Object

rubocop:disable Naming/AccessorMethodName



88
89
90
# File 'lib/bolt/target.rb', line 88

def set_resource(resource)
  inventory_target.set_resource(resource)
end

#target_aliasObject



75
76
77
# File 'lib/bolt/target.rb', line 75

def target_alias
  inventory_target.target_alias
end

#to_hObject

rubocop:enable Naming/AccessorMethodName



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/bolt/target.rb', line 93

def to_h
  options.to_h.merge(
    'name' => name,
    'uri' => uri,
    'protocol' => protocol,
    'user' => user,
    'password' => password,
    'host' => host,
    'port' => port
  )
end

#to_sObject



63
64
65
# File 'lib/bolt/target.rb', line 63

def to_s
  safe_name
end

#transportObject



144
145
146
# File 'lib/bolt/target.rb', line 144

def transport
  inventory_target.transport
end

#transport_configObject Also known as: options



148
149
150
# File 'lib/bolt/target.rb', line 148

def transport_config
  inventory_target.transport_config.to_h
end

#uriObject



132
133
134
# File 'lib/bolt/target.rb', line 132

def uri
  inventory_target.uri
end

#userObject



157
158
159
# File 'lib/bolt/target.rb', line 157

def user
  inventory_target.user
end

#varsObject



55
56
57
# File 'lib/bolt/target.rb', line 55

def vars
  @inventory.vars(self)
end