Skip to content

Commit

Permalink
Use ansible-runner instead of ansible-playbook
Browse files Browse the repository at this point in the history
Use ansible-runner instead of ansible-playbook
  • Loading branch information
Ladas committed Jul 10, 2018
1 parent 6bf5eca commit 761c3af
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/ansible/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ def run(env_vars, extra_vars, playbook_path)
private

def run_via_cli(env_vars, extra_vars, playbook_path)
result = AwesomeSpawn.run!(ansible_command, :env => env_vars, :params => [{:extra_vars => JSON.dump(extra_vars)}, playbook_path])
prepare_tmp_structure

result = AwesomeSpawn.run!(ansible_command, :env => env_vars, :params => [{:cmdline => "--extra-vars '#{JSON.dump(extra_vars)}'", :playbook => playbook_path}])
JSON.parse(result.output)
end

def prepare_tmp_structure
base_dir = "/tmp/ansible-runner/"
mkdir(base_dir)
mkdir(base_dir + 'project') # without this, there is a silent fail of the ansible-runner command see https://github.com/ansible/ansible-runner/issues/88
end

def mkdir(base_dir)
Dir.mkdir(base_dir) unless Dir.exist?(base_dir)
end

def ansible_command
# TODO add possibility to use custom path, e.g. from virtualenv
"ansible-playbook"
"ansible-runner run /tmp/ansible-runner --json"
end
end
end
Expand Down

0 comments on commit 761c3af

Please sign in to comment.