# complete ansible command line verbose like display using the python API

**URL:** <https://forum.ansible.com/t/complete-ansible-command-line-verbose-like-display-using-the-python-api/27172>\
**Category:** Ansible Developer\
**Created:** [April 3, 2018, 5:53am UTC](https://forum.ansible.com/t/complete-ansible-command-line-verbose-like-display-using-the-python-api/27172 "2018-04-03T05:53:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suren\_Baskaran](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@Suren\_Baskaran](https://forum.ansible.com/u/Suren_Baskaran)\
**Post date:** [April 3, 2018, 5:53am UTC](https://forum.ansible.com/t/complete-ansible-command-line-verbose-like-display-using-the-python-api/27172/1 "2018-04-03T05:53:29Z")

</div>

Hi

So when we run a ansible playbook in command line with -vvv [verbosity=3] we get all these below information like “Task path” , “using module” and the internals of how each hosts gets connectivity established.

TASK [SHOW THE LAST 10 ALERTS] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: XXXXXXXX  
Using module file /usr/lib/python2.7/site-packages/ansible/modules/commands/command.py  
\<[gmcrou07.uk.db.com](http://gmcrou07.uk.db.com)\> ESTABLISH SSH CONNECTION FOR USER: XXXX  
\<[gmcrou07.uk.db.com](http://gmcrou07.uk.db.com)\> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=tpeng -o ConnectTimeout=10 -o ControlPath=XXXXXX ‘/bin/sh -c ‘"’“‘echo ~ && sleep 0’”’"‘’  
\<[gmcrou07.uk.db.com](http://gmcrou07.uk.db.com)\> (255, ‘’, ‘ssh: connect to host XXXXXX port 22: Connection timed out\r\n’)  
fatal: [[gmcrou07.uk.db.com](http://gmcrou07.uk.db.com)]: UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: ssh: connect to host XXXX port 22: Connection timed out\r\n”,  
“unreachable”: true  
}

Whereas when I set the same verbosity using the python API , I just an detailed info why the SSH failed to connect like below

Failed to connect to the host via ssh: OpenSSH\_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh\_config\r\ndebug1: /etc/ssh/ssh\_config line 1: Applying options for \*\r\ndebug1: /etc/ssh/ssh\_config line 4: Deprecated option "rhostsauthentication"\r\ndebug1: /etc/ssh/ssh\_config line 8: Deprecated option "fallbacktorsh"\r\ndebug1: /etc/ssh/ssh\_config line 9: Deprecated option "usersh"\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket "/home/eqops\_dev/.ansible/cp/26dab4b3e8" does not exist\r\ndebug2: resolving "XXXXXXXXX" port 22\r\ndebug2: ssh\_connect\_direct: needpriv 0\r\ndebug1: Connecting to [gmcrou07.uk.db.com](http://gmcrou07.uk.db.com) [10.236.110.107] port 22.\r\ndebug2: fd 3 setting O\_NONBLOCK\r\ndebug1: connect to address XXXXXx port 22: Connection timed out\r\nssh: connect to host XXXXXX port 22: Connection timed out

but not the other details , not sure if am missing any callback settings.

Appreciate some help here.

---

<div class="post-metadata">

**Author:** ![Suren\_Baskaran](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@Suren\_Baskaran](https://forum.ansible.com/u/Suren_Baskaran)\
**Post date:** [April 3, 2018, 11:31am UTC](https://forum.ansible.com/t/complete-ansible-command-line-verbose-like-display-using-the-python-api/27172/2 "2018-04-03T11:31:30Z")

</div>

Or in short - how to add get a command line like verbose using the API

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [April 3, 2018, 2:47pm UTC](https://forum.ansible.com/t/complete-ansible-command-line-verbose-like-display-using-the-python-api/27172/3 "2018-04-03T14:47:39Z")

</div>

Which python API? For what purposes? (ie, writing an ansible plugin? module? some other tool?)

The python code that is used by the ansible application (for ex, the ‘ansible.parsing.dataloader’ python module) isn’t  
intended to be used by other applications. ie, there is no consideration given to forwards or backwards compatibility  
of those interfaces. They were also never designed to be used outside of the app. Nothing in particular prevents that  
but it is not a good API for that use (for example, the way ‘display’ and ‘verbosity’ works makes assumptions about  
**main** setting up a ‘display’ instance and other code referencing ‘display’ from **main** in many places).  
The API will break a lot and often.

To quote the docs ([http://docs.ansible.com/ansible/latest/dev\_guide/developing\_api.html](http://docs.ansible.com/ansible/latest/dev_guide/developing_api.html)):

“Please note that while we make this API available it is not intended for direct consumption, it is here for the support of the Ansible command line tools. We try not to make breaking changes but we reserve the right to do so at any time if it makes sense for the Ansible toolset.”

If the code you are writing is an ansible plugin, I would suggest using as little of the ansible python API as possible. ie, not much beyondthe plugin base classes.

If writing a separate app, I would not use the ansible python API at all.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 3, 2018, 5:06pm UTC](https://forum.ansible.com/t/complete-ansible-command-line-verbose-like-display-using-the-python-api/27172/4 "2018-04-03T17:06:21Z")

</div>

In this case you seem to be missing code to handle the  
v2\_runner\_on\_unreachable event.

---

<div class="post-metadata">

**Author:** ![Suren\_Baskaran](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@Suren\_Baskaran](https://forum.ansible.com/u/Suren_Baskaran)\
**Post date:** [April 3, 2018, 5:38pm UTC](https://forum.ansible.com/t/complete-ansible-command-line-verbose-like-display-using-the-python-api/27172/5 "2018-04-03T17:38:20Z")

</div>

Thanks for the reply Brian

Unfortunately I do have it , it gives me all valid Output for the verbose

But the one thing I seem to miss is the - ansible versions , task paths , module paths , and host tasks details , ran meta handlers that comes with a ansible command line verbose

Thanks,  
Suren VB
