delete example ldap db

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
   shell: grep Example /var/lib/ldap/DB_CONFIG.example
   register: exampleDB
   ignore_errors: TRUE

- name: delete example db
   shell: rm /var/lib/ldap/*
   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

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

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

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.