-5

I have just written an Ansible task to run an update script:

- name: Run Tdarr Updater
  command: grep -r /opt/tdarr/Tdarr_Updater | grep [INFO]
  register: updater_result

- name: Show Output 
  debug: msg="{{ updater_result.stdout_lines }}"

It works just fine, but I am unhappy with the output, check this screenshot:

enter image description here

I need only the lines with [INFO], the others ones are not interessting...

When I run /opt/tdarr/Tdarr_Updater | grep [INFO], I receive the output that I wanted:

[2022-01-01T22:31:31.614] [INFO] Tdarr_Updater - Tdarr_Updater | v2.00.12
[2022-01-01T22:31:31.615] [INFO] Tdarr_Updater - Tdarr_Updater | Required platform_arch:linux_x64
[2022-01-01T22:31:31.616] [INFO] Tdarr_Updater -
[2022-01-01T22:31:31.616] [INFO] Tdarr_Updater -
[2022-01-01T22:31:31.617] [INFO] Tdarr_Updater - Tdarr_Node | Current version: 2.00.12 | Required version: 2.00.12
[2022-01-01T22:31:31.617] [INFO] Tdarr_Updater - Tdarr_Node | Up to date! Version: 2.00.12!
[2022-01-01T22:31:31.618] [INFO] Tdarr_Updater -
[2022-01-01T22:31:31.619] [INFO] Tdarr_Updater -
[2022-01-01T22:31:31.619] [INFO] Tdarr_Updater - Tdarr_Server | Current version: 2.00.12 | Required version: 2.00.12
[2022-01-01T22:31:31.619] [INFO] Tdarr_Updater - Tdarr_Server | Up to date! Version: 2.00.12!
[2022-01-01T22:31:31.620] [INFO] Tdarr_Updater -
[2022-01-01T22:31:31.620] [INFO] Tdarr_Updater - Finished!

How can I save the grep output into the register?

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
  • 4
    Please edit your question and add the **code, logs, output, error messages... in the question body as code blocks**. Using images for this has [numerous disadvantages](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557) and is specifically listed as a bad practice in the must read help article [How to ask](/help/how-to-ask). Thanks – Zeitounator Jan 02 '22 at 11:05

1 Answers1

0

Because of the pipe | in your command you may have a look into whats the difference between ansible raw, shell and command?

It can be used if you want to execute more complex commands, for example commands concatenated with pipes

and use

- name: Run Tdarr Updater
  shell:
    cmd: grep -r /opt/tdarr/Tdarr_Updater | grep [INFO]
  changed_when: false
  register: updater_result

Further readings

U880D
  • 8,601
  • 6
  • 24
  • 40
  • 1
    Thank You for the link! `- name: Run Tdarr Updater shell: /opt/tdarr/Tdarr_Updater | grep [INFO] register: updater_result` did the trick :) – David Stegmüller Jan 03 '22 at 23:21