Module: Ansible
- Defined in:
- lib/rbbt/workflow/integration/ansible.rb,
lib/rbbt/workflow/integration/ansible/workflow.rb
Defined Under Namespace
Modules: AnsibleWorkflow
Class Method Summary collapse
- .clean_symbols(hash) ⇒ Object
- .play(playbook, inventory = nil) ⇒ Object
- .playbook(file, task = nil, options = {}) ⇒ Object
- .workflow2playbook(workflow, task, options = {}) ⇒ Object
Class Method Details
.clean_symbols(hash) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rbbt/workflow/integration/ansible.rb', line 18 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 |
.play(playbook, inventory = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rbbt/workflow/integration/ansible.rb', line 5 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 |
.playbook(file, task = nil, options = {}) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/rbbt/workflow/integration/ansible.rb', line 46 def self.playbook(file, task = nil, = {}) task = 'default' if task.nil? workflow = Workflow.require_workflow file task = workflow.tasks.keys.last if workflow.tasks[task].nil? workflow2playbook workflow, task, end |
.workflow2playbook(workflow, task, options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rbbt/workflow/integration/ansible.rb', line 35 def self.workflow2playbook(workflow, task, = {}) = workflow.get_SOPT(workflow.tasks[task]) tasks = workflow.job(task, nil, ).exec hosts = [:hosts] || 'localhost' clean_tasks = tasks.collect{|task| self.clean_symbols task } {"hosts" => hosts, "tasks" => clean_tasks} end |