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, #initialize, validates

Constructor Details

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

Instance Method Details

#to_hObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ansible/ruby/models/play.rb', line 28

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