deploy_db.yml 1.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---

- name: copy database indexing script if defined
  copy: src={{ sentinel_mongodb_js_script }} dest={{ sentinel_dir }} owner={{ sentinel_user }} group={{ sentinel_user }} mode=0644
  when: sentinel_mongodb_js_script is defined

- name: run database indexing script
  shell: /usr/bin/mongo --quiet {{ mongodb_conf_bind_ip }}:{{ mongodb_conf_port }}/sentinel {{ sentinel_dir }}/{{ sentinel_mongodb_js_script }} -u {{ mongodb_root_name }} -p {{ mongodb_root_password }} --authenticationDatabase admin
  when: sentinel_mongodb_js_script is defined
  register: js_index_script
  changed_when: js_index_script.stdout != ""

- name: check if api users exist
  shell: "/usr/bin/mongo --quiet -u {{ mongodb_root_name }} -p {{ mongodb_root_password }} --authenticationDatabase admin --eval \"db.users.find({id: '{{ item.id }}'}).count()\" sentinel || true"
  register: api_users_exist
  changed_when: api_users_exist.stdout != "1" or api_users_exist.rc != 0
  with_items:
    - "{{ sentinel_api_users }}"
  when: sentinel_api_users is defined and sentinel_api_users

- name: copy users config script if required
  template: src=sentinelUsersSetup.js.j2 dest={{ sentinel_dir }}/sentinelUsersSetup.js owner={{ sentinel_user }} group={{ sentinel_user }} mode=0600
  when: api_users_exist|changed

- name: run api users config script if required
  shell: /usr/bin/mongo --quiet {{ mongodb_conf_bind_ip }}:{{ mongodb_conf_port }}/sentinel {{ sentinel_dir }}/sentinelUsersSetup.js -u {{ mongodb_root_name }} -p {{ mongodb_root_password }} --authenticationDatabase admin
  register: api_users
  changed_when: api_users.stdout != ""
  when: api_users_exist|changed

- name: remove api users config script if present
  file: path={{ sentinel_dir }}/sentinelUsersSetup.js state=absent
  when: api_users_exist|changed