Skip to content

Commit

Permalink
[Ansible::Runner] wait on artifacts/ to exist
Browse files Browse the repository at this point in the history
Before returning a result, wait on the `artifacts/` directory to be
created before returning a response object.

This will ensure that calling `.running?` will return `false` properly
when the `ansible-runner` has ended, and not before it has even had a
chance to start.

Thanks for Jason for the find on this bug.
  • Loading branch information
NickLaMuro committed Oct 7, 2020
1 parent 30a0e1a commit 1cb36ed
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/ansible/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def run_via_cli(hosts, credentials, env_vars, extra_vars, tags: nil, ansible_run
begin
fetch_galaxy_roles(playbook_or_role_args)
result = AwesomeSpawn.run("ansible-runner", :env => env_vars_hash, :params => params)
wait_on(File.join(base_dir, "artifacts"))
res = response(base_dir, ansible_runner_method, result)
ensure
# Clean up the tmp dir for the sync method, for async we will clean it up after the job is finished and we've
Expand Down Expand Up @@ -377,6 +378,13 @@ def python3_modules_path
def determine_existing_python_paths_for(*paths)
paths.select { |path| File.exist?(path) }
end

def wait_on(dir)
100.times do
Dir.exists?(dir)
sleep(0.1)
end
end
end
end
end

0 comments on commit 1cb36ed

Please sign in to comment.