Sha256: f01b27d247aae59d25e6037da9693f26f801363df9b2cc3380366c7bedc5ef28
Contents?: true
Size: 1.34 KB
Versions: 24
Compression:
Stored size: 1.34 KB
Contents
require_relative 'ansible/workflow' require 'rbbt/workflow/usage' module Ansible def self.play(playbook, inventory = nil) inventory = Rbbt.etc.ansible_inventory.find Log.with_severity 0 do TmpFile.with_file do |tmp| if Hash === playbook Open.write(tmp, [playbook].to_yaml) playbook = tmp end CMD.cmd_log("ansible-playbook -i #{inventory} #{playbook}") end end end def self.clean_symbols(hash) new = {} hash.each do |key,value| key = key.to_s value = case value when Symbol value.to_s when Hash self.clean_symbols(value) else value end new[key] = value end new end def self.workflow2playbook(workflow, task, options = {}) job_options = workflow.get_SOPT(workflow.tasks[task]) tasks = workflow.job(task, nil, job_options).exec hosts = options[:hosts] || 'localhost' clean_tasks = tasks.collect{|task| self.clean_symbols task } {"hosts" => hosts, "tasks" => clean_tasks} end def self.playbook(file, task = nil, options = {}) task = 'default' if task.nil? workflow = Workflow.require_workflow file task = workflow.tasks.keys.last if workflow.tasks[task].nil? workflow2playbook workflow, task, options end end
Version data entries
24 entries across 24 versions & 1 rubygems