Skip to content

Forward ansible-runner subprocess stderr to job output - #111

Open
adamruzicka wants to merge 3 commits into
theforeman:masterfrom
adamruzicka:error
Open

Forward ansible-runner subprocess stderr to job output#111
adamruzicka wants to merge 3 commits into
theforeman:masterfrom
adamruzicka:error

Conversation

@adamruzicka

Copy link
Copy Markdown
Contributor

Runner::Parent#publish_data is a no-op, so stderr from the subprocess was silently discarded. This change overrides the process manager callbacks to route stderr through broadcast_data instead, making errors such as "ansible-runner: command not found" visible in the job output.

Normal playbook output is captured via artifact files, so ansible-runner's direct stdout/stderr is redundant. The -q flag silences it, ensuring only genuine errors (e.g. command not found) reach the stderr broadcast path.

Original
image

Patched - ansible-runner missing
image

Patched - ansible-runner available, but ansible-playbook missing (this comes from ansible-runner's artifacts)
image

@adamruzicka

Copy link
Copy Markdown
Contributor Author

CI should be addressed by #112

@jakduch jakduch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#112 has been merged now, so I think rebasing should get the Ruby CI running again. The Redmine check will probably still need an issue reference in the commit message.

@process_manager.stdin.close unless @process_manager.done?
end

def set_process_manager_callbacks(pm)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add a small regression test for this callback, perhaps checking that stderr is passed to broadcast_data? That would help protect the main behavior of this change.

env['FOREMAN_CALLBACK_DISABLE'] = '1' if @rex_command
env['SMART_PROXY_ANSIBLE_ENVIRONMENT_FILE'] = Proxy::Ansible::Plugin.settings[:ansible_environment_file]
command = ['ansible-runner', 'run', @root, '-p', 'playbook.yml']
command = ['ansible-runner', '-q', 'run', @root, '-p', 'playbook.yml']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the same test could also verify that the generated command includes -q, since that is important for avoiding duplicate output.

Add two regression tests as requested in PR review:
1. Test that set_process_manager_callbacks routes stderr to broadcast_data
2. Test that start_ansible_runner includes the -q flag in the command

These tests protect the main behavior of the PR from future regressions.
@jakduch

jakduch commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Thanks for considering my review and making the changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants