Skip to content

Commit

Permalink
Use AwesomeSpawn to call the ansible command
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladas committed Jun 14, 2018
1 parent e42216c commit b743114
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions lib/ansible/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,14 @@ def run(env_vars, extra_vars, playbook_path)
private

def run_via_cli(env_vars, extra_vars, playbook_path)
result = %x(#{format_env_vars(env_vars)} #{ansible_command.shellescape} #{format_extra_vars(extra_vars)} #{playbook_path.to_s.shellescape})
JSON.parse(result)
result = AwesomeSpawn.run!(ansible_command, :env => env_vars, :params => [{:extra_vars => JSON.dump(extra_vars)}, playbook_path])
JSON.parse(result.output)
end

def ansible_command
# TODO add possibility to use custom path, e.g. from virtualenv
"ansible-playbook"
end

def format_env_vars(env_vars)
env_vars.map { |key, value| "#{key.shellescape}='#{value.shellescape}'" }.join(" ")
end

def format_extra_vars(extra_vars)
"--extra-vars '#{JSON.dump(extra_vars)}'"
end
end
end
end

0 comments on commit b743114

Please sign in to comment.