how to prevent Ansible from showing output on screen?
This can be done by judicious use of one of the Ansible callback plugins. 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:
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
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.
Related videos on Youtube
Comments
-
BlackCrystal over 1 year
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?