2

When I use like ansible-playbook -vvvv, it shows all stdout for all running tasks. Though what it also shows, is noise that shows how each command is run through SSH.

Is there a way to use verbosity to just show tasks stdout without any other noise?

Currently it shows output like this:

<myhost> ESTABLISH SSH CONNECTION FOR USER: root
<myhost> SSH: EXEC ssh -vvv -o ControlMaster=auto -o ControlPersist=30m -o PreferredAuthentications=publickey -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/tmp/ansible-ssh-%h-%p-%r myhost '/bin/sh -c '"'"'rm -f -r /var/tmp/ansible-tmp-1333333.89364-1154635-13434444/ > /dev/null 2>&1 && sleep 0'"'"''
<myhost> (0, b'', b'OpenSSH_8.2p1 Ubuntu-4ubuntu0.4, OpenSSL 1.1.1f  31 Mar 2020\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 1136353\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
changed: [dev] => {
    "changed": true,
    "cmd": [
        "/opt/odoo/.local/bin/docker-compose",
        "rm",
        "-fsv",
        "odoo"
    ],
    "delta": "0:00:03.287055",
    "end": "2022-01-25 08:09:25.105235",
    "invocation": {
        "module_args": {
            "_raw_params": "/opt/odoo/.local/bin/docker-compose rm -fsv odoo",
            "_uses_shell": false,
            "argv": null,
            "chdir": "/opt/odoo/app",
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": false
        }
    },
    "msg": "",
    "rc": 0,
    "start": "2022-01-25 08:09:21.818180",
    "stderr": "Stopping app_odoo_1 ... \r\nStopping app_odoo_1 ... done\r\nRemoving app_odoo_1 ... \r\nRemoving app_odoo_1 ... done",
    "stderr_lines": [
        "Stopping app_odoo_1 ... ",
        "Stopping app_odoo_1 ... done",
        "Removing app_odoo_1 ... ",
        "Removing app_odoo_1 ... done"
    ],
    "stdout": "Going to remove app_odoo_1",
    "stdout_lines": [
        "Going to remove app_odoo_1"
    ]
}

Is there a way to just keep JSON part without explicitly specifying debug arg for each task?

U880D
  • 8,601
  • 6
  • 24
  • 40
Andrius
  • 19,658
  • 37
  • 143
  • 243

1 Answers1

0

When using Ansible in Verbose Mode like ansible-playbook -vvvv, it shows how each command is run through SSH and it also shows all stdout for all running tasks.

verbose mode (-vvv for more, -vvvv to enable connection debugging)

This is so far the intended behavior.

Is there a way to use verbosity to just show tasks stdout without any other noise?

Even the parameters -v or -vv producing a kind of noise. This is also the intended behavior since the feature is for debugging functionality outside of tasks. See in example source query vvv or source query verbose.

Is there a way to just keep JSON part without explicitly specifying debug arg for each task?

I am not aware of any feature like that.

Currently I assume it would be necessary to use the debug_module. Or using the Playbook Debugger to Debugging tasks. With that it would be possible to get the stdout of a task only.

Further Readings


Aside from Ansible there might be a way of filtering the output in example via | grep -A2 stdout or awk 'p; / =>/ {p=1}', sed '0,/ => /d' and than | jq -M -r '.stdout', respective | jq -M -r '.stdout_lines'.

Thanks to

U880D
  • 8,601
  • 6
  • 24
  • 40