You could also use the "slurp" module, and register the full file contents,
and use

when: foo.contents | match(regexp)

I think Paul's suggestion is clearer and easier though, and transfers less
over the wire.




On Thu, May 1, 2014 at 4:27 PM, Paul Durivage <[email protected]>wrote:

> I think what you'd want to do here is use the shell module to check for
> the regex with grep, emphasis on "I think".  You could also use the exit
> code, since grep exits with a 0 when it matches lines, 1 if no match is
> found.  This is probably easier.
>
>     - name: Check if file has Fred
>       shell: grep 'fred' /path/to/file
>       register: grep
>
>     - name: Do this if we find Fred
>       debug: msg="We found Fred"
>       when: grep.stdout
>
>
>
>
> On Thu, May 1, 2014 at 9:11 AM, Peter Leggett <[email protected]>wrote:
>
>>  Hi,
>>
>> how can i execute a ansible task only if a file contains a specfic regexp
>> ?
>> I was hoping to use the when: statement as follows :-
>>
>> - name: do this task only if file contains fred
>>   command: some command
>>   when: file contains "fred"
>>
>> Can something like this work ? Thanks for any help.
>>
>> Pete
>>
>>  --
>> 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/cd6273a1-3a1b-45c0-b6c9-54dcd4e7fa84%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/cd6273a1-3a1b-45c0-b6c9-54dcd4e7fa84%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> 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/CAK6JQEEUOnxL2YDm4oTh1_snQ24ugcqB4j2WJ5kPEPoP8X0Tnw%40mail.gmail.com<https://groups.google.com/d/msgid/ansible-project/CAK6JQEEUOnxL2YDm4oTh1_snQ24ugcqB4j2WJ5kPEPoP8X0Tnw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CA%2BnsWgyfyFThB4e4ftaaJJgiZ12MARmaF_-OzKYvB%2BAkOUm0XQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to