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, #vars

Methods inherited from Base

#jinja, #method_missing

Constructor Details

#initialize(name, context, temp_counter_inc) ⇒ Task

Returns a new instance of Task.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 13

def initialize(name, context, temp_counter_inc)
  super()
  @name = name
  @context = context
  @module = nil
  @inclusion = nil
  # Until the variable is utilized, we don't know if 'register' should be set, the supplied lambda
  name_fetcher = lambda do
    name = "result_#{temp_counter_inc.call}"
    @task_args[:register] = name
    name
  end
  @register = Result.new name_fetcher
end

Dynamic Method Handling

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

Instance Method Details

#_registerObject



88
89
90
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 88

def _register
  @register
end

#_resultObject

allow for other attributes besides the module in any order



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 93

def _result
  args = {
    name: @name
  }.merge @task_args
  args[:module] = @module if @module
  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



59
60
61
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 59

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

#changed_when(clause) ⇒ Object



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

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

#connection(value) ⇒ Object



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

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

#delegate_to(value) ⇒ Object



76
77
78
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 76

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

#failed_when(clause) ⇒ Object



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

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

#local_actionObject



71
72
73
74
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 71

def local_action
  @task_args[:local_action] = true
  yield
end

#no_log(value) ⇒ Object



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

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

#notify(value) ⇒ Object



67
68
69
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 67

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

#poll(value) ⇒ Object



63
64
65
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 63

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

#remote_user(value) ⇒ Object



80
81
82
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 80

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

#respond_to_missing?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 84

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

#validate?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 105

def validate?
  true
end

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

Yields:

  • ([hash_key, hash_value])


44
45
46
47
48
49
50
51
# File 'lib/ansible/ruby/dsl_builders/task.rb', line 44

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:



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

def with_items(*clause)
  # 1 arg is probably a variable reference, so don't use an array
  @task_args[:with_items] = clause.length == 1 ? clause[0] : clause
  yield JinjaItemNode.new if block_given?
end