Class: VagrantBolt::Config::Bolt

Inherits:
Global
  • Object
show all
Defined in:
lib/vagrant-bolt/config/bolt.rb

Instance Attribute Summary collapse

Attributes inherited from Global

#bolt_exe, #boltdir, #connect_timeout, #debug, #facts, #features, #host_key_check, #machine_alias, #machine_name, #modulepath, #password, #port, #private_key, #project, #run_as, #ssl, #ssl_verify, #sudo_password, #tmpdir, #user, #vars, #verbose

Instance Method Summary collapse

Methods inherited from Global

#bolt_exe_path, #inventory_config, #setting_map

Constructor Details

#initializeBolt

Returns a new instance of Bolt.



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vagrant-bolt/config/bolt.rb', line 55

def initialize
  super
  @args         = UNSET_VALUE
  @name         = UNSET_VALUE
  @nodes        = []
  @excludes     = []
  @node_list    = UNSET_VALUE
  @params       = UNSET_VALUE
  @command      = UNSET_VALUE
  @targets      = []
  @target_list  = UNSET_VALUE
end

Instance Attribute Details

#argsString

Returns Additional arguments for the bolt command.

Returns:

  • (String)

    Additional arguments for the bolt command



6
7
8
# File 'lib/vagrant-bolt/config/bolt.rb', line 6

def args
  @args
end

#commandSymbol

Returns Which command bolt should use. task, plan, command.

Returns:

  • (Symbol)

    Which command bolt should use. task, plan, command



38
39
40
# File 'lib/vagrant-bolt/config/bolt.rb', line 38

def command
  @command
end

#excludesArray<String, Symbol>

Note: The node_list will override this setting. Note: This will be merged with targets, with excludes taking precidence. Valid values are an array of machine names.

Returns:

  • (Array<String, Symbol>)

    The targets to exclude from running this task or plan on.



24
25
26
# File 'lib/vagrant-bolt/config/bolt.rb', line 24

def excludes
  @excludes
end

#nameString

Returns The name of task or plan to run.

Returns:

  • (String)

    The name of task or plan to run



10
11
12
# File 'lib/vagrant-bolt/config/bolt.rb', line 10

def name
  @name
end

#node_listString

DEPRECATED. Use target_list instead. This setting overrides nodes and needs to be in the protocol://ipaddress:port URI format.

Returns:

  • (String)

    The bolt node list. This defaults to the currnet machine.



30
31
32
# File 'lib/vagrant-bolt/config/bolt.rb', line 30

def node_list
  @node_list
end

#nodesArray<String, Symbol>, "ALL"

DEPRECATED. Use targets instead. Note: The node_list will override this setting. Valid values are an array of machine names or the string "ALL".

Returns:

  • (Array<String, Symbol>, "ALL")

    The nodes to run the task or plan on.



17
18
19
# File 'lib/vagrant-bolt/config/bolt.rb', line 17

def nodes
  @nodes
end

#noopBoolean

Returns If the command should be run with noop. Only valid with tasks and apply.

Returns:

  • (Boolean)

    If the command should be run with noop. Only valid with tasks and apply.



42
43
44
# File 'lib/vagrant-bolt/config/bolt.rb', line 42

def noop
  @noop
end

#paramsHash

Returns The paramater hash for the task or plan.

Returns:

  • (Hash)

    The paramater hash for the task or plan



34
35
36
# File 'lib/vagrant-bolt/config/bolt.rb', line 34

def params
  @params
end

#target_listString

This setting overrides targets and needs to be in the protocol://ipaddress:port URI format.

Returns:

  • (String)

    The bolt target list. This defaults to the currnet machine.



53
54
55
# File 'lib/vagrant-bolt/config/bolt.rb', line 53

def target_list
  @target_list
end

#targetsArray<String, Symbol>, "ALL"

Note: The target_list will override this setting. Valid values are an array of machine names or the string "ALL".

Returns:

  • (Array<String, Symbol>, "ALL")

    The targets to run the task or plan on.



48
49
50
# File 'lib/vagrant-bolt/config/bolt.rb', line 48

def targets
  @targets
end

Instance Method Details

#blacklistArray<String>

Return a list of settings that are not applicable to the bolt command line options

Returns:

  • (Array<String>)

    An array of settings to ignore when creating a bolt command



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/vagrant-bolt/config/bolt.rb', line 126

def blacklist
  [
    'nodes',
    'targets',
    'excludes',
    'node_list',
    'target_list',
    'bolt_exe',
    'args',
    'command',
    'name',
    'vars',
    'facts',
    'features',
    'boltdir',
    'run_as',
  ]
end

#finalize!Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/vagrant-bolt/config/bolt.rb', line 68

def finalize!
  @bolt_exe       = nil if @bolt_exe == UNSET_VALUE
  @boltdir        = nil if @boltdir == UNSET_VALUE
  super
  @args           = nil if @args == UNSET_VALUE
  @name           = nil if @name == UNSET_VALUE
  @node_list      = nil if @node_list == UNSET_VALUE
  @params         = nil if @params == UNSET_VALUE
  @command        = nil if @command == UNSET_VALUE
  @noop           = nil if @noop == UNSET_VALUE
  # Use nodes if targets is not specified.
  @targets        = @nodes if @targets.empty?
  @target_list    = @node_list if (@target_list == UNSET_VALUE) || @target_list.nil?
end

#merge(other) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/vagrant-bolt/config/bolt.rb', line 83

def merge(other)
  super.tap do |result|
    new_excludes = (excludes + other.excludes.dup).flatten.uniq
    result.instance_variable_set(:@excludes, new_excludes.to_a)
    unless targets.to_s.casecmp("all").zero?
      new_targets = (targets + other.targets.dup).flatten.uniq
      result.instance_variable_set(:@targets, new_targets.to_a)
    end
  end
end

#validate(_machine) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/vagrant-bolt/config/bolt.rb', line 94

def validate(_machine)
  errors = _detected_errors
  errors << I18n.t('vagrant-bolt.config.bolt.errors.invalid_command', command: @command.to_s) if !@command.nil? && !['task', 'plan', 'command'].include?(@command.to_s)

  if @targets.nil? || (!(@targets.is_a? Array) && !@targets.to_s.casecmp("all").zero?)
    errors << I18n.t('vagrant-bolt.config.bolt.errors.invalid_data_command',
                     item: 'targets',
                     command: 'array')
  end

  if @excludes.nil? || !(@excludes.is_a? Array)
    errors << I18n.t('vagrant-bolt.config.bolt.errors.invalid_data_command',
                     item: 'excludes',
                     command: 'array')
  end

  if @command.nil? && !@name.nil?
    errors << I18n.t('vagrant-bolt.config.bolt.errors.command_not_specified')
  elsif !@command.nil? && @name.nil?
    errors << I18n.t('vagrant-bolt.config.bolt.errors.no_task_or_plan')
  end

  if @command.to_s != 'task' && @noop
    errors << I18n.t('vagrant-bolt.config.bolt.errors.noop_compatibility',
                     command: @command)
  end

  { "Bolt" => errors }
end