Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ansible does not expand newline and linefeed characters in verbose SSH output

When debugging an Ansible playbook, I occasionally need to use verbose mode to debug the connection itself, like in this call:

ansible-playbook -vvvv -i inventories/whatever playbook_under_test.yml

This will, among the debug info from Ansible itself, also output everything that SSH -vvvv would print. However, on the terminal, all newlines and linefeeds from this SSH debug output are represented by escape sequences, which makes the output a huge and rather unreadable unstructured block of text:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<192.168.1.2> (255, b'', b'OpenSSH_8.7p1, OpenSSL 1.1.1q FIPS 5 Jul 2022\r\nd
ebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug3: /etc/ssh/ssh
_config line 55: Including file /etc/ssh/ssh_config.d/50-redhat.conf depth 0\
r\ndebug1: Reading configuration data /etc/ssh/ssh_config.d/50-redhat.conf\r\
ndebug2: checking match for \'final all\' host 192.168.1.2 originally 192.168
.1.2\r\ndebug3: /etc/ssh/ssh_config.d/50-redhat.conf line 3: not matched \'fi
nal\'\r\ndebug2: match not found\r\ndebug3: /etc/ssh/ssh_config.d/50-redhat.c
onf line 5: Including file /etc/crypto-policies/back-ends/openssh.config dept
h 1 (parse only)\r\ndebug1: Reading configuration data /etc/crypto-policies/b
ack-ends/openssh.config\r\ndebug3: gss kex names ok: [gss-curve25519-sha256-,
gss-nistp256-sha256-,gss-group14-sha256-,gss-group16-sha512-,gss-gex-sha1-,gs
s-group14-sha1-,gss-group1-sha1-]\r\ndebug3: kex names ok: [curve25519-sha256
,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2

(wrapped at 78 columns for readability here, output is abbreviated and anonymized).

How can I configure my Ansible setup so that those \r\n escape sequences are actually printed out as proper linebreaks on my terminal?

>Solution :

How can I configure my Ansible setup so that those \r\n escape sequences are actually printed out as proper linebreaks on my terminal?

Create an ansible.cfg file from the location you run Ansible.

>  cat ansible.cfg
[defaults]
stdout_callback = yaml
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading