Am Donnerstag, 12. Oktober 2017 11:34:17 UTC+2 schrieb David Searle:
>
> Hi all,
>
> I am fairly new to ansible but have been googling around for the answer to 
> this and just cannot find anything that matches my request. So I wonder if 
> you can assist please??
>
>
> Basically I have a very long playbook to build an environment and set 
> permissions etc etc etc and I have been instructed that at the very 
> beginning of the PB I need to set a condition that IF a certain directory 
> already contains files (any files at all) then the PB should exit, else it 
> should continue with the rest of the installation and other bits.
>
> How on earth do I do that sort of thing?? I just cannot see a module that 
> helps me apart from it something that checks that the directory exists 
> which is not what I want.
>

> Thanks for any constructive input.
>
>
>
With 2 to 3 tasks i guess:

# http://docs.ansible.com/ansible/latest/find_module.html

  - name: Find files in {{ path }}
    find:
      paths: "{{ path }}"

      patterns: '*.*'

    register: foundFiles

# http://docs.ansible.com/ansible/latest/meta_module.html

   - meta: end_play
     when: foundFiles.matched > 0

Optionally you could insert a debug msg task between these two, to write 
sth. like "ending play".

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/f489326d-e4cc-4ca2-b24e-502cf973af46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to