Skip to content

add a callback to print verbatim output#408

Draft
evgeni wants to merge 4 commits intomasterfrom
callbackhack
Draft

add a callback to print verbatim output#408
evgeni wants to merge 4 commits intomasterfrom
callbackhack

Conversation

@evgeni
Copy link
Member

@evgeni evgeni commented Mar 13, 2026

No description provided.

@evgeni
Copy link
Member Author

evgeni commented Mar 13, 2026

% ./foremanctl features                   
FEATURE                   STATE        DESCRIPTION
foreman                   enabled      Base Foreman Server
foreman-proxy             enabled      Base Foreman Proxy
katello                   enabled      Content and Subscription Management plugin for Foreman
hammer                    available    Foreman CLI
google                    available    Google Compute Engine plugin for Foreman
azure_rm                  available    Azure Resource Manager plugin for Foreman


def v2_playbook_on_start(self, playbook):
playbook_filename = basename(playbook._file_name)
if playbook_filename == 'features.yaml':
Copy link
Member

Choose a reason for hiding this comment

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

This is probably the only ugly part since additional playbooks wanting this kind of output would require an entry here. That would be nice to somehow indicate in the playbook or the metadata for a given command but I think we could solve that later since this achieves the goal pretty cleanly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. The problem is that the "read playbook metadata" step in obsah happens after Ansible (and callbacks) is initialized, as we use Ansible to parse the playbook for information. @arvind4501 also had issues with that in theforeman/obsah#107

def v2_runner_on_ok(self, result):
if self.FALLBACK_TO_DEFAULT:
super().v2_runner_on_ok(result)
else:
Copy link
Member

@ShimShtein ShimShtein Mar 15, 2026

Choose a reason for hiding this comment

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

Since you only want to change the on_ok behavior, maybe instead of catching the playbook name, you can access the task object via the result, and extract the parameters of the task object. If you can add arbitrary params to the task, you will be able to do something like:

- task1:
  verbatim_print: true

and then catch it from here:

if result._task.params[verbatim_print]
  ....
else
  super().v2_runner_on_ok(result)

This way we won't need to store the FALLBACK_TO_DEFAULT in all the other hooks.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants