summaryrefslogtreecommitdiffstats
path: root/deploy/adapters/ansible/roles/database/tasks/mongodb_config.yml
blob: 10f0322c635e6b9635ba3f916b00c92efbaff480 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
##############################################################################
# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
---
- name: copy mongo js
  template:
    src: '{{ item.src }}'
    dest: '{{ item.dest }}'
  with_items:
    - src: replica.js
      dest: /opt/replica.js

- name: init replica servers
  shell: mongo compass /opt/replica.js

- name: wait replica servers are ready
  shell: |
    mongo compass --eval 'printjson(rs.status())'| \
        grep -E 'PRIMARY|SECONDARY'| wc -l
  register: servers
  until: servers.stdout|int == {{ haproxy_hosts|length }}
  retries: 60
  delay: 10

- debug: msg='{{ servers.stdout |int }}'

- name: wait replica servers are ready
  shell: mongo compass --eval 'printjson(rs.status())'|grep -E 'PRIMARY'|wc -l
  register: servers
  until: servers.stdout|int == 1
  retries: 60
  delay: 10

- debug: msg='{{ servers.stdout |int }}'

- name: Add admin user
  mongodb_user:
    login_host: "{{ internal_vip.ip }}"
    database: admin
    name: root
    password: root
    roles: 'root'
    state: present

- name: create mongodb user and db
  mongodb_user:
    login_host: "{{ internal_vip.ip }}"
    login_user: root
    login_password: root
    database: ceilometer
    name: ceilometer
    password: "{{ CEILOMETER_DBPASS }}"
    roles: 'readWrite,dbAdmin'
    state: present

- name: grant user privilege
  mongodb_user:
    login_host: "{{ internal_vip.ip }}"
    login_user: root
    login_password: root
    database: ceilometer
    name: ceilometer
    password: "{{ CEILOMETER_DBPASS }}"
    roles: 'readWrite,dbAdmin'
    state: present