Ansible API

Hi all,

As I mentioned in a previous email, we are using ansible from a python
program to creates and configure HPC clusters on a cloud using, of
course, ansible.

The reason why I am writing is because we would like to filter the
output from ansible, and displaying it only if a reasonable amount of
`-v` options are given. However, we couldn't find an easy way to do
it.

This is the code we are using:

        stats = callbacks.AggregateStats()
        playbook_cb = callbacks.PlaybookCallbacks(verbose=0)
        runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=0)

        pb = PlayBook(
            playbook=self._playbook_path,
            host_list=inventory_path,
            remote_user=self._remote_user,
            callbacks=playbook_cb,
            runner_callbacks=runner_cb,
            stats=stats,
            sudo=self._sudo,
            sudo_user=self._sudo_user,
            private_key_file=self._private_key_file,
        )

        status = pb.run()

while the code of PlaybookCallbacks contains a lot of `print`
statements. I could monkey patch ansible.callbacks.banner and
ansible.callbacks.stringc, but it's very ugly and it will still print
a newline for each `print` statement.

I wonder if there is a better way to solve this issue, and if there is
no way currently, I would like to ask you if you would accept a pull
request to replace the `print` statements with functions that can be
configured (or overridden).

.a.

You can subclass the callback or provide your own implementation, or additionally log with an additional logging callback plugin.

I see there is a `DefaultRunnerCallbacks` class that does not print
anything, wouldn't it nice to have also a `DefaultPlaybookCallbacks`
that does not print anything as well?

Not really, as the main project does not have a use for such things.

You can pass in a class of your own design though.