Method: MCollective::Util::Playbook::Tasks#run_task
- Defined in:
- lib/mcollective/util/playbook/tasks.rb
#run_task(task, set, hooks = true) ⇒ Boolean
Runs a specific task
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/mcollective/util/playbook/tasks.rb', line 53 def run_task(task, set, hooks=true) properties = task[:properties] result = task[:result] task_runner = task[:runner] Log.info("About to run task: %s" % t(task[:runner].description)) result.description = t(task[:runner].description) if hooks && !run_set("pre_task") Log.warn("Failing task because a critical pre_task hook failed") return false end if properties["pre_sleep"] Log.info("Sleeping %d seconds before check" % [properties["pre_sleep"]]) sleep(Integer(properties["pre_sleep"])) end (1..properties["tries"]).each do |try| task_runner.from_hash(t(properties)) task_runner.validate_configuration! @results << result.timed_run(set) if result.success? Log.info(result.msg) else Log.error(result.msg) end if try != properties["tries"] && !result.success Log.warn("Task failed on try %d/%d, sleeping %ds: %s" % [try, properties["tries"], properties["try_sleep"], result.msg]) sleep(Integer(properties["try_sleep"])) end break if result.success end if hooks && !run_set("post_task") Log.warn("Failing task because a critical post_task hook failed") return false end result.success end |