Class: Bolt::Target2

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) ⇒ Target2

rubocop:enable Lint/UnusedMethodArgument



34
35
36
37
# File 'lib/bolt/target.rb', line 34

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.



106
107
108
# File 'lib/bolt/target.rb', line 106

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) ⇒ 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



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bolt/target.rb', line 21

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)
  from_asserted_hash('uri' => uri)
end

.from_asserted_hash(hash) ⇒ Object

Target.new from a plan initialized with a hash



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

def self.from_asserted_hash(hash)
  inventory = Puppet.lookup(:bolt_inventory)
  target = inventory.create_target_from_plan(hash)
  new(target.name, inventory)
end

Instance Method Details

#configObject



61
62
63
# File 'lib/bolt/target.rb', line 61

def config
  inventory_target.config
end

#detailObject



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/bolt/target.rb', line 85

def detail
  {
    'name' => name,
    'uri' => uri,
    'alias' => target_alias,
    'config' => Bolt::Util.deep_merge(config, 'transport' => transport, transport => options),
    'vars' => vars,
    'features' => features,
    'facts' => facts,
    'plugin_hooks' => plugin_hooks
  }
end

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

Returns:

  • (Boolean)


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

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

#factsObject



53
54
55
# File 'lib/bolt/target.rb', line 53

def facts
  @inventory.facts(self)
end

#feature_setObject

Use feature_set internally to access set



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

def feature_set
  @inventory.features(self)
end

#featuresObject

features returns an array to be compatible with plans



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

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

#hostObject



102
103
104
# File 'lib/bolt/target.rb', line 102

def host
  inventory_target.host
end

#inventory_targetObject



98
99
100
# File 'lib/bolt/target.rb', line 98

def inventory_target
  @inventory.targets[@name]
end

#optionsObject



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

def options
  inventory_target.options
end

#passwordObject



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

def password
  inventory_target.password
end

#plugin_hooksObject



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

def plugin_hooks
  inventory_target.plugin_hooks
end

#portObject



116
117
118
# File 'lib/bolt/target.rb', line 116

def port
  inventory_target.port
end

#protocolObject



124
125
126
# File 'lib/bolt/target.rb', line 124

def protocol
  inventory_target.protocol
end

#remote?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/bolt/target.rb', line 112

def remote?
  protocol == 'remote'
end

#safe_nameObject



65
66
67
# File 'lib/bolt/target.rb', line 65

def safe_name
  inventory_target.safe_name
end

#target_aliasObject



69
70
71
# File 'lib/bolt/target.rb', line 69

def target_alias
  inventory_target.target_alias
end

#to_hObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/bolt/target.rb', line 73

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

#to_sObject



57
58
59
# File 'lib/bolt/target.rb', line 57

def to_s
  safe_name
end

#transportObject



120
121
122
# File 'lib/bolt/target.rb', line 120

def transport
  inventory_target.protocol
end

#uriObject



108
109
110
# File 'lib/bolt/target.rb', line 108

def uri
  inventory_target.uri
end

#userObject



128
129
130
# File 'lib/bolt/target.rb', line 128

def user
  inventory_target.user
end

#varsObject



49
50
51
# File 'lib/bolt/target.rb', line 49

def vars
  @inventory.vars(self)
end