I just raised this issue with Ansible which has been immediately closed.

https://github.com/ansible/ansible/issues/16194

I'm going to copy / paste my report verbatim so as to avoid repeating 
myself all over again (hopefully the formatting doesn't screw up).


ISSUE TYPE
   
   - Bug Report

ANSIBLE VERSION

ansible 2.2.0 (devel 3bac945147) last updated 2016/06/03 21:47:13 (GMT +100)
  lib/ansible/modules/core: (detached HEAD 2bd8d78a8b) last updated 2016/06/04 
08:22:55 (GMT +100)
  lib/ansible/modules/extras: (detached HEAD b0aec50b9a) last updated 
2016/06/04 08:23:00 (GMT +100)
  config file = /home/john/git/ansible-dsh/tests/ansible.cfg
  configured module search path = Default w/o overrides

CONFIGURATION

export ANSIBLE_STDOUT_CALLBACK=dsh
OS / ENVIRONMENT

N/A
SUMMARY

The Ansible ad-hoc CLI command (simply called ansible) does not respect the 
setting of the ANSIBLE_STDOUT_CALLBACK environment variable. This makes it 
impossible to customise the output using my own callback plugin.

For example, I have written a callback plugin called dsh (a development 
version can be found here 
<https://github.com/lqueryvg/ansible-dsh/blob/master/tests/callback_plugins/dsh.py>)
 
which formats output in a similar fashion to the distributed shell command.
STEPS TO REPRODUCE

mkdir callback_plugins
# copy my custom dsh.py plugin into the `callback_plugins` directory
export ANSIBLE_STDOUT_CALLBACK=myplugin
export ANSIBLE_HOST_KEY_CHECKING=False

ansible -i hosts all -m ping

EXPECTED RESULTS

I expect my dsh plugin to be used, to create output as follows:

host1: Wed Jun  8 19:55:49 UTC 2016
host2: Wed Jun  8 19:55:49 UTC 2016

ACTUAL RESULTS

The usual minimal plugin is used instead.

host1 | SUCCESS | rc=0 >>
Wed Jun  8 19:55:35 UTC 2016

host2 | SUCCESS | rc=0 >>
Wed Jun  8 19:55:35 UTC 2016

<https://github.com/bcoca>

In Brian's response he said:

In any case, this is by design, there is an additional setting 
(bin_ansible_callbacks) to specifically force it to do so.
I've tried this and it didn't make the blindest bit of difference.

The code responsible for selecting the callback plugin in cli/adhoc.py 
looks like this:


        if self.callback: 
            cb = self.callback
        elif self.options.one_line:
            cb = 'oneline'
        else:
            cb = 'minimal'


I.e. it doesn't observe any configuration variables or environment 
variables as per the usual configuration mechanism which can be found in 
constants.py.
If I modify the above lines in adhoc.py to look like this, it works.

        if self.callback: 
            cb = self.callback
        elif self.options.one_line:
            cb = 'oneline'
        else:
            from ansible.compat.six.moves import configparser
            cb = C.get_config(configparser.ConfigParser, 'defaults', 
'stdout_callback',
                  'ANSIBLE_STDOUT_CALLBACK', 'minimal')


Can Brian or anyone else help ?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5f5d3e19-773c-43cc-af1b-af7cd4f05976%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to