ansible ad-hoc cli command does not respect ANSIBLE_STDOUT_CALLBACK

103 views
Skip to first unread message

John Buxton

unread,
Jun 8, 2016, 4:29:19 PM6/8/16
to Ansible Project
I just raised this issue with Ansible which has been immediately closed.


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) 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

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 ?
Reply all
Reply to author
Forward
0 new messages