Ansible 2.8 hanging with bash command

23 views
Skip to first unread message

John

unread,
Mar 5, 2020, 12:31:05 PM3/5/20
to Ansible Project
I have a task that searches logs for specific errors in various logs (up to 7 days worth of logs).  When searching through just one log I never had an issue, but when searching through the 7 logs (used a wildcard to accomplish this), sometimes Ansible goes to lunch and doesn't recover.  It just sits there like it is still executing.  We have let it run for many hours in that state just to make sure.  I think it has a lot to do with timing and/or the size of the files (and the number of errors found int he files).  Wondering if there is a more robust way to address this so that it will either not hang, continue on after a certain point (maybe a 5 minute timeout) or be more efficient (such as searching logs and writing to a file with an ansible module I don't know of)?  

- name: Gather error reports
  shell: |
          while read line; do
            grep -i "$line" "{{ log_source }}"* | uniq  > "{{ dest_dir }}/{{ ansible_hostname }}-$line.txt"
          done < "{{ error_log }}"
  failed_when: false
  args:
    executable: /bin/bash


John

unread,
Mar 5, 2020, 2:20:54 PM3/5/20
to Ansible Project
I am using the following.  Not sure if there is a better solution:

- name: Gather error reports in background
  shell: |
          while read line; do
            grep -i "$line" "{{ log_source }}"* | uniq  > "{{ dest_dir }}/{{ ansible_hostname }}-$line.txt"
          done < "{{ error_log }}"
  failed_when: false
  args:
    executable: /bin/bash
  async: 180
  poll: 0
  register: gather_sleeper

- name:  Check on report gathering -- This can take a while
  async_status:
    jid: "{{ gather_sleeper.ansible_job_id }}"
  register: job_result
  until: job_result.finished
  retries: 37
  failed_when: false


Stefan Hornburg (Racke)

unread,
Mar 6, 2020, 7:42:00 AM3/6/20
to ansible...@googlegroups.com
I would recommend to use a dedicated tool such as logwatch.

Regards
Racke


>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/af6c88f5-5270-4c57-839e-0205547b31b7%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/af6c88f5-5270-4c57-839e-0205547b31b7%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc
Reply all
Reply to author
Forward
0 new messages