Class: Ansible::Ruby::DslBuilders::Task

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

Instance Method Summary collapse

Methods inherited from Unit

#ansible_when, #become, #become_user, #ignore_errors

Methods inherited from Base

#jinja, #method_missing

Constructor Details

#initialize(name, context, temp_counter) ⇒ Task

Returns a new instance of Task.



11
12
13
14
15
16
17
18
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 11

def initialize(name, context, temp_counter)
  super()
  @name = name
  @context = context
  @module = nil
  @inclusion = nil
  @temp_counter = temp_counter
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ansible::Ruby::DslBuilders::Base

Instance Method Details

#_resultObject

allow for other attributes besides the module in any order



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 62

def _result
  args = {
    module: @module,
    name: @name
  }.merge @task_args
  args[:inclusion] = @inclusion if @inclusion
  task = @context.new args
  # Quick feedback if the type is wrong, etc.
  task.validate! if validate?
  task
end

#async(value) ⇒ Object



45
46
47
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 45

def async(value)
  @task_args[:async] = value
end

#changed_when(clause) ⇒ Object



24
25
26
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 24

def changed_when(clause)
  @task_args[:changed_when] = clause
end

#failed_when(clause) ⇒ Object



28
29
30
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 28

def failed_when(clause)
  @task_args[:failed_when] = clause
end

#no_log(value) ⇒ Object



20
21
22
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 20

def no_log(value)
  @task_args[:no_log] = value
end

#notify(value) ⇒ Object



53
54
55
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 53

def notify(value)
  @task_args[:notify] = value
end

#poll(value) ⇒ Object



49
50
51
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 49

def poll(value)
  @task_args[:poll] = value
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 57

def respond_to_missing?(*)
  !@module || super
end

#validate?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 74

def validate?
  true
end

#with_dict(clause) {|[hash_key, hash_value]| ... } ⇒ Object

Yields:

  • ([hash_key, hash_value])


32
33
34
35
36
37
38
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 32

def with_dict(clause)
  @task_args[:with_dict] = clause
  return unless block_given?
  hash_key = JinjaItemNode.new('item.key')
  hash_value = JinjaItemNode.new('item.value')
  yield [hash_key, hash_value]
end

#with_items(clause) {|JinjaItemNode.new| ... } ⇒ Object

Yields:



40
41
42
43
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 40

def with_items(clause)
  @task_args[:with_items] = clause
  yield JinjaItemNode.new if block_given?
end