<p>If you just want to print a subset of the results of your commands on your terminal without using one or more <code>-v</code> flags, you can refactor your playbook to show just the standard output from each of the commands using a JSON query. For example:</p>
<pre class="lang-yaml prettyprint-override"><code>---
- name: display info
  hosts: localhost
  tasks:
  - name: Display uptime and kernel info
    shell: &quot;{{ item }}&quot;
    with_items:
      - uptime
      - uname -n
      - uname -r
    register: output

  - debug: msg=&quot;{{ output.results | json_query('[].stdout[]') }}&quot;
</code></pre>
<p>This will yield output similar to the following:</p>
<pre><code>PLAY [display info] **********************************************************************************

TASK [Gathering Facts] *******************************************************************************
ok: [localhost]

TASK [Display uptime and kernel info] ****************************************************************
changed: [localhost] =&gt; (item=uptime)
changed: [localhost] =&gt; (item=uname -n)
changed: [localhost] =&gt; (item=uname -r)

TASK [debug] *****************************************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: [
        &quot;22:48  up 4 days,  3:41, 2 users, load averages: 1.26 1.39 1.42&quot;,
        &quot;localhost.local&quot;,
        &quot;20.3.0&quot;
    ]
}

PLAY RECAP *******************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
</code></pre>

CC BY-SA 4.0
2021-02-06T16:55:59.997Z
Thank you very much for you great help.   Michael.
Michael
CC BY-SA 4.0
2021-02-06T03:57:51.697Z
2021-02-06T03:57:51.697Z
CodeGnome
<p>I was trying to display a few commands with  .stdout - the gives me the mixed output also with   &quot;item&quot;</p>
<p>with item it gives me:</p>
<p>just the strings:</p>
<p>uname -a</p>
<p>uptime</p>
<p>but not the output of those commands</p>
<p>this is the play-book with commented stuff there that does not work:</p>
<pre><code>    - name: To Display === UPTIME and KERNEL Version ===
#    - name: &quot;To Display === {{ item }}&quot;
      command: &quot;{{ item }}&quot;
      loop:
        - uname -n
        - uptime -p
        - uname -r


#        command: uname -n
#      shell: uptime -p; uname -r; rpm -qa --last kernel
#      register: OUTPUT
#    - debug: msg=&quot;{{ OUTPUT.stdout('\n') }}&quot;
#    - debug: msg=&quot;{{OUTPUT.stdout}}&quot;
#    - debug: var=&quot;{{OUTPUT.stdout}}&quot;
#      shell: &quot;{{item}}&quot;
#      with_items: ['hostname', 'whoami']
#        - uptime -p
#
#        - uname -r
#        - rpm -qa --last kernel
...
</code></pre>

<ansible>
trying to display 3 - 5 commands
Michael
# trying to display 3 - 5 commands

(Asked by: username_0 on 2021-02-05)

I was trying to display a few commands with  .stdout - the gives me the mixed output also with   "item"
with item it gives me:
just the strings:
uname -a
uptime
but not the output of those commands
this is the play-book with commented stuff there that does not work:
    - name: To Display === UPTIME and KERNEL Version ===
#    - name: "To Display === {{ item }}"
      command: "{{ item }}"
      loop:
        - uname -n
        - uptime -p
        - uname -r


#        command: uname -n
#      shell: uptime -p; uname -r; rpm -qa --last kernel
#      register: OUTPUT
#    - debug: msg="{{ OUTPUT.stdout('\n') }}"
#    - debug: msg="{{OUTPUT.stdout}}"
#    - debug: var="{{OUTPUT.stdout}}"
#      shell: "{{item}}"
#      with_items: ['hostname', 'whoami']
#        - uptime -p
#
#        - uname -r
#        - rpm -qa --last kernel
...

**Tags:** ansible


---

## 1 answers

### Answer by username_1 on 2021-02-06. Score: 2

If you just want to print a subset of the results of your commands on your terminal without using one or more -v flags, you can refactor your playbook to show just the standard output from each of the commands using a JSON query. For example:
---
- name: display info
  hosts: localhost
  tasks:
  - name: Display uptime and kernel info
    shell: "{{ item }}"
    with_items:
      - uptime
      - uname -n
      - uname -r
    register: output

  - debug: msg="{{ output.results | json_query('[].stdout[]') }}"

This will yield output similar to the following:
PLAY [display info] **********************************************************************************

TASK [Gathering Facts] *******************************************************************************
ok: [localhost]

TASK [Display uptime and kernel info] ****************************************************************
changed: [localhost] => (item=uptime)
changed: [localhost] => (item=uname -n)
changed: [localhost] => (item=uname -r)

TASK [debug] *****************************************************************************************
ok: [localhost] => {
    "msg": [
        "22:48  up 4 days,  3:41, 2 users, load averages: 1.26 1.39 1.42",
        "localhost.local",
        "20.3.0"
    ]
}

PLAY RECAP *******************************************************************************************
localhost                  : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

> **Comments:**
> **username_0**: Thank you very much for you great help.   username_0.  

---

