<p>This can be done by judicious use of one of the <a href="https://docs.ansible.com/ansible/latest/plugins/callback.html" rel="nofollow noreferrer">Ansible callback plugins</a>. Set the relevant configuration in your <code>ansible.cfg</code> file.</p>

<p>You have a few options... </p>

<p>In order to print <em>nothing</em> to the screen, you can use the <a href="https://docs.ansible.com/ansible/latest/plugins/callback/null.html" rel="nofollow noreferrer">null callback</a>:</p>

<blockquote>
  <p>This callback prevents outputing events to screen</p>
</blockquote>

<p>However, this may be overkill and doesn't do what you want, which is to write the output to a file. This can be done with either of the </p>

<ul>
<li><a href="https://docs.ansible.com/ansible/latest/plugins/callback/tree.html" rel="nofollow noreferrer">tree</a> or</li>
<li><a href="https://docs.ansible.com/ansible/latest/plugins/callback/log_plays.html" rel="nofollow noreferrer">log_plays</a></li>
</ul>

<p>modules.</p>

<p>I would probably suggest the log_plays module in your case.</p>

<p>Note: This is going straight from the documentation. I haven't used the tree or log_plays plugin myself, opting either for the yaml or profile_tasks one, to make things more readable. It also seems like you want to filter <em>just a part</em> of the output, not all of it. You may want to use a combination of filters in order to get the desired effect.</p>

CC BY-SA 4.0
2019-12-15T12:51:49.347Z
2019-12-15T12:51:49.347Z
Bruce Becker
<p>I have this in my playbook which execute a command on remote server and enters its log on local server.</p>

<pre><code> - name: run script
   shell: runuser -l testuser -c "/tmp/test.sh"
   register: myshell_output
 - name: copy output to a local file
   lineinfile:
     dest: /thesaurus/output
     line: "{{ item }}"
     insertafter: EOF
   with_items:
    - "#####################Beginning##########################"
    - "{{ myshell_output.stdout }}"
    - "########################END#############################"
   delegate_to: localhost
</code></pre>

<p>the output is always shown on screen and troubleshooting gets hard and distracting.  </p>

<pre><code>TASK [run script] ************
changed: [1.1.1.1]
changed: [2.2.2.2]
TASK [copy output to a local file] ***********
changed: [1.1.1.1 -&gt; localhost] =&gt; 
(item=#####################Beginning##########################)
 ok: [2.2.2.2 -&gt; localhost] =&gt; 
(item=#####################Beginning##########################)
{
  REALLY LONG AND BIG OUTPUT!
}
changed: [1.1.1.1 -&gt; localhost] =&gt; 
(item=########################END#############################)
ok: [2.2.2.2 -&gt; localhost] =&gt; 
(item=########################END#############################)
</code></pre>

<p>is it possible to prevent Ansible from printing these output on screen and just insert output to a file?</p>

<ansible><linux><yaml><centos>
how to prevent Ansible from showing output on screen?
BlackCrystal
# how to prevent Ansible from showing output on screen?

(Asked by: username_0 on 2019-12-15)

I have this in my playbook which execute a command on remote server and enters its log on local server.
 - name: run script
   shell: runuser -l testuser -c "/tmp/test.sh"
   register: myshell_output
 - name: copy output to a local file
   lineinfile:
     dest: /thesaurus/output
     line: "{{ item }}"
     insertafter: EOF
   with_items:
    - "#####################Beginning##########################"
    - "{{ myshell_output.stdout }}"
    - "########################END#############################"
   delegate_to: localhost

the output is always shown on screen and troubleshooting gets hard and distracting.  
TASK [run script] ************
changed: [1.1.1.1]
changed: [2.2.2.2]
TASK [copy output to a local file] ***********
changed: [1.1.1.1 -> localhost] => 
(item=#####################Beginning##########################)
 ok: [2.2.2.2 -> localhost] => 
(item=#####################Beginning##########################)
{
  REALLY LONG AND BIG OUTPUT!
}
changed: [1.1.1.1 -> localhost] => 
(item=########################END#############################)
ok: [2.2.2.2 -> localhost] => 
(item=########################END#############################)

is it possible to prevent Ansible from printing these output on screen and just insert output to a file?

**Tags:** ansible, linux, yaml, centos


---

## 1 answers

### Answer by username_1 on 2019-12-15. Score: 2 | Accepted answer

This can be done by judicious use of one of the [Ansible callback plugins](https://docs.ansible.com/ansible/latest/plugins/callback.html). Set the relevant configuration in your `ansible.cfg` file.

You have a few options...

In order to print *nothing* to the screen, you can use the [null callback](https://docs.ansible.com/ansible/latest/plugins/callback/null.html):

> This callback prevents outputing events to screen

However, this may be overkill and doesn't do what you want, which is to write the output to a file. This can be done with either of the

* [tree](https://docs.ansible.com/ansible/latest/plugins/callback/tree.html) or
* [log\_plays](https://docs.ansible.com/ansible/latest/plugins/callback/log_plays.html)

modules.

I would probably suggest the log\_plays module in your case.

Note: This is going straight from the documentation. I haven't used the tree or log\_plays plugin myself, opting either for the yaml or profile\_tasks one, to make things more readable. It also seems like you want to filter *just a part* of the output, not all of it. You may want to use a combination of filters in order to get the desired effect.


---

