# with blockinfile module, I'm looking for option to check the entries whether its present or not! if not then entries have to be added by play.

**URL:** <https://forum.ansible.com/t/with-blockinfile-module-im-looking-for-option-to-check-the-entries-whether-its-present-or-not-if-not-then-entries-have-to-be-added-by-play/29762>\
**Category:** Ansible Project\
**Created:** [February 25, 2019, 1:08pm UTC](https://forum.ansible.com/t/with-blockinfile-module-im-looking-for-option-to-check-the-entries-whether-its-present-or-not-if-not-then-entries-have-to-be-added-by-play/29762 "2019-02-25T13:08:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepan\_M](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Deepan\_M](https://forum.ansible.com/u/Deepan_M)\
**Post date:** [February 25, 2019, 1:08pm UTC](https://forum.ansible.com/t/with-blockinfile-module-im-looking-for-option-to-check-the-entries-whether-its-present-or-not-if-not-then-entries-have-to-be-added-by-play/29762/1 "2019-02-25T13:08:36Z")

</div>

Hello,

Can someone please help to solve my request?

with blockinfile module, I’m looking for option to check the entries whether its present or not! if not then entries have to be added by play.

As per below my playbook, its working partially, like its appending even if the entries are already present but actually i’m looking that play should ignore if already entries are exists and incase not present then it should added.

**Playbook:-**  
cat resolv\_add.yml

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [February 25, 2019, 1:36pm UTC](https://forum.ansible.com/t/with-blockinfile-module-im-looking-for-option-to-check-the-entries-whether-its-present-or-not-if-not-then-entries-have-to-be-added-by-play/29762/2 "2019-02-25T13:36:01Z")

</div>

> Hello,
> 
> Can someone please help to solve my request?
> 
> with blockinfile module, I'm looking for option to check the entries  
> whether its present or not! if not then entries have to be added by play.
> 
> As per below my playbook, its working partially, like its appending even if  
> the entries are already present but actually i'm looking that play should  
> ignore if already entries are exists and incase not present then it should  
> added.

My guess is that it is finding the empty string marker at BOF and finding nothing between the zero length marker and itself, this adding the block unconditionally. You will have more luck with a non empty marker.

V/r,  
James Cassell

---

<div class="post-metadata">

**Author:** ![Deepan\_M](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@Deepan\_M](https://forum.ansible.com/u/Deepan_M)\
**Post date:** [February 25, 2019, 3:19pm UTC](https://forum.ansible.com/t/with-blockinfile-module-im-looking-for-option-to-check-the-entries-whether-its-present-or-not-if-not-then-entries-have-to-be-added-by-play/29762/3 "2019-02-25T15:19:02Z")

</div>

Thank you James, its working fine.

Thanks,  
Deepan M
