# delete example ldap db

**URL:** <https://forum.ansible.com/t/delete-example-ldap-db/14161>\
**Category:** Ansible Project\
**Created:** [December 16, 2013, 4:41pm UTC](https://forum.ansible.com/t/delete-example-ldap-db/14161 "2013-12-16T16:41:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Patermann](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Marc\_Patermann](https://forum.ansible.com/u/Marc_Patermann)\
**Post date:** [December 16, 2013, 4:41pm UTC](https://forum.ansible.com/t/delete-example-ldap-db/14161/1 "2013-12-16T16:41:43Z")

</div>

Hi,

I'm building a playbook to install and configure openldap on SLES.  
The original openldap server installs an example db at /var/lib/ldap.

This files have to be removed, before I can install my own db.

What is the best way to delete the example db (once)?

I tried with tasks like

- name: check for example db  
&nbsp;&nbsp;&nbsp;shell: grep Example /var/lib/ldap/DB\_CONFIG.example  
&nbsp;&nbsp;&nbsp;register: exampleDB  
&nbsp;&nbsp;&nbsp;ignore\_errors: TRUE

- name: delete example db  
&nbsp;&nbsp;&nbsp;shell: rm /var/lib/ldap/\*  
&nbsp;&nbsp;&nbsp;when: exampleDB|success

This works. "delete example db" is skipped, if there is no DB\_CONFIG.example anymore.

But I always get the "failed" for "check for example db" for the second (and further) run(s), which is why I have to ignore it.  
Is there any way to circumvent this?

Marc

---

<div class="post-metadata">

**Author:** ![David\_Karban](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@David\_Karban](https://forum.ansible.com/u/David_Karban)\
**Post date:** [December 16, 2013, 4:47pm UTC](https://forum.ansible.com/t/delete-example-ldap-db/14161/2 "2013-12-16T16:47:23Z")

</div>

Hi,

how many files are there? You are writing “This files have to be removed”, but you are testing only one file.

If it is only several files, maybe just delete them by file module like this:

- name: Ensure example db do not exists

file: name={{ ‘/var/lib/ldap/’ + item }} state=absent

with\_items:

- DB\_CONFIG.example

- DB\_CONFIG.example1

…

?

David

---

<div class="post-metadata">

**Author:** ![Marc\_Patermann](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Marc\_Patermann](https://forum.ansible.com/u/Marc_Patermann)\
**Post date:** [December 16, 2013, 4:52pm UTC](https://forum.ansible.com/t/delete-example-ldap-db/14161/3 "2013-12-16T16:52:43Z")

</div>

David,

David Karban schrieb (16.12.2013 17:47 Uhr):

> how many files are there? You are writing "This files have to be removed", but you are testing only one file.

The problem is, that most of the files will have the same name in the "production" database. The DB\_CONFIG.example is (the) one file which will not the used later. And thats why it is a good indicator for an existing example database.

> If it is only several files, maybe just delete them by file module  
> like this: - name: Ensure example db do not exists file: name={{  
> '/var/lib/ldap/' + item }} state=absent with\_items: -  
> DB\_CONFIG.example - DB\_CONFIG.example1

That is not possible. See above. I would delete production files later.

Marc

---

<div class="post-metadata">

**Author:** ![David\_Karban](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@David\_Karban](https://forum.ansible.com/u/David_Karban)\
**Post date:** [December 16, 2013, 5:12pm UTC](https://forum.ansible.com/t/delete-example-ldap-db/14161/4 "2013-12-16T17:12:24Z")

</div>

I see,

in that case, notify when you install ldap (only if you use state=present, not state=latest, that would wipe db`s at every openldap upgrade).

yum: name=openldap state=present

notify: remove\_test\_db

Or use stat module in the “check for example db”, it should not failed status that you get with grep.
