how to execute a handler if a file is found

10 views
Skip to first unread message

Dan Idar

unread,
May 19, 2020, 3:29:32 PM5/19/20
to Ansible Project
Hello
I would like to be able to find the files that are bigger than a certain dize and then restart a service if this happens because it mean the rotation is not working after the configurtion update

the find module does not 'change' when the file is found or not and i know i can trigger a change using
when_changed: true



per instance:

---

- hosts: all
  gather_facts
: false
  handlers
:
   
- name: start service
     command
: service auditd restart
     args
:
       warn
: false
     

  tasks
:
     
- name: find files
       find
:
         path
: /var/log
         patterns
: '*.log'
         size
: 100m
       
register: bigfiles


       

how would I execute the handler and the find files task never changes

i only want to start the service on server that have such big files..

thanks

Matt Martz

unread,
May 19, 2020, 3:34:28 PM5/19/20
to ansible...@googlegroups.com
Maybe something like this:

     - name: find files
       find:
         path: /var/log
         patterns: '*.log'
         size: 100m
       register: bigfiles
       changed_when: bigfiles.files != []
       notify: start service


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0236f5ba-ae30-4100-ba5b-3b170f655859%40googlegroups.com.


--
Matt Martz
@sivel
sivel.net

Dick Visser

unread,
May 19, 2020, 4:47:14 PM5/19/20
to ansible...@googlegroups.com
On Tue, 19 May 2020 at 21:29, Dan Idar <dan78...@gmail.com> wrote:
>
> Hello
> I would like to be able to find the files that are bigger than a certain dize and then restart a service if this happens because it mean the rotation is not working after the configurtion update

Ansible would also be a great tool to prevent breakage like "rotation
is not working after configuration update" from occurring in the first
place.
You might want to fix that, at some point.
Reply all
Reply to author
Forward
0 new messages