Class: Ansible::Ruby::Models::Play

Inherits:
Base
  • Object
show all
Defined in:
lib/ansible/ruby/models/play.rb

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 Method Details

#to_hObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ansible/ruby/models/play.rb', line 40

def to_h
  result = super
  hosts = result.delete :hosts
  tasks = result.delete :items
  roles = result.delete :roles
  name = result.delete :name
  # Be consistent with Ansible order
  new_result = {
    hosts: [*hosts].join(':') # Ansible doesn't specify this as an array
  }
  new_result[:name] = name if name
  new_result[:tasks] = tasks.is_a?(Array) ? tasks : [tasks] if tasks # ensure we have an array
  new_result[:roles] = [*roles] if roles # ensure we have an array
  result.each do |key, value|
    new_result[key] = value
  end
  new_result
end