Class: Ansible::Ruby::Models::Task

Inherits:
Unit
  • Object
show all
Defined in:
lib/ansible/ruby/models/task.rb

Direct Known Subclasses

Handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attr_option, attr_options, attribute, fix_inclusion, #initialize, remove_existing_validations, validates

Constructor Details

This class inherits a constructor from Ansible::Ruby::Models::Base

Instance Attribute Details

#local_actionObject

:reek:Attribute - This is a simple flag



42
43
44
# File 'lib/ansible/ruby/models/task.rb', line 42

def local_action
  @local_action
end

Instance Method Details

#to_hObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ansible/ruby/models/task.rb', line 48

def to_h
  result = super
  # Module gets referenced by name, may not have a module though
  mod_or_include = @inclusion ? :inclusion : :module
  flatten = result.delete(mod_or_include) || {}
  # Module traditionally goes right after name, so rebuilding hash
  new_result = {
    name: result.delete(:name)
  }
  if @local_action
    module_name = flatten.keys.first
    flatten = {
      local_action: {
        module: module_name.to_s
      }.merge(flatten[module_name])
    }
  end
  new_result.merge! flatten
  result.each do |key, value|
    new_result[key] = value
  end
  # If we have a block at this level, get rid of the duplicate {block: block{}}, we'e reusing playbook blocks here
  new_result[:block] = new_result[:block][:block] if new_result[:block]
  new_result[:rescue] = new_result[:rescue][:block] if new_result[:rescue]
  new_result
end