Duong Ha-Quang 2ade45e1c7 Fix Creating Ceilometer MongoDB database failed
The check whether 'already' presents in mongodb output
should belong to changed_when.

Change-Id: Ib982a59820d53ccf5439f59df50c1b1938650967
Closes-Bug: #1641113
2017-02-28 08:54:01 +00:00

69 lines
2.7 KiB
YAML

---
- name: Creating Ceilometer MongoDB database
command: docker exec -t mongodb mongo --host {{ ceilometer_database_mongodb_address }} --eval 'db = db.getSiblingDB("{{ ceilometer_database_name }}"); db.createUser({user':' "{{ ceilometer_database_user }}", pwd':' "{{ ceilometer_database_password }}", roles':' [ "readWrite", "dbAdmin" ]})'
register: mongodb_ceilometer_database
run_once: true
changed_when: "{{ 'already' not in mongodb_ceilometer_database.stdout }}"
failed_when: "{{ mongodb_ceilometer_database.stdout.split()[4] != 'connecting' }}"
delegate_to: "{{ groups['mongodb'][0] }}"
when:
- ceilometer_database_type == "mongodb"
- name: Checking Ceilometer mysql database
kolla_toolbox:
module_name: mysql_db
module_args:
login_host: "{{ ceilometer_database_mysql_address }}"
login_port: "{{ ceilometer_database_port }}"
login_user: "{{ ceilometer_database_user }}"
login_password: "{{ ceilometer_database_password }}"
name: "{{ ceilometer_database_name }}"
register: mysql_access
failed_when: False
changed_when: False
run_once: True
when:
- ceilometer_database_type == "mysql"
- name: Creating Ceilometer mysql database
kolla_toolbox:
module_name: mysql_db
module_args:
login_host: "{{ database_address }}"
login_port: "{{ database_port }}"
login_user: "{{ database_user }}"
login_password: "{{ database_password }}"
name: "{{ ceilometer_database_name }}"
register: mysql_ceilometer_database
run_once: True
delegate_to: "{{ groups['ceilometer-api'][0] }}"
when:
- ceilometer_database_type == "mysql"
- "'FAILED' in mysql_access.stdout"
- name: Creating Ceilometer database user and setting permissions
kolla_toolbox:
module_name: mysql_user
module_args:
login_host: "{{ database_address }}"
login_port: "{{ database_port }}"
login_user: "{{ database_user }}"
login_password: "{{ database_password }}"
name: "{{ ceilometer_database_name }}"
password: "{{ ceilometer_database_password }}"
host: "%"
priv: "{{ ceilometer_database_name }}.*:ALL"
append_privs: "yes"
run_once: True
delegate_to: "{{ groups['ceilometer-api'][0] }}"
when:
- ceilometer_database_type == "mysql"
- "'FAILED' in mysql_access.stdout"
# TODO(Jeffrey4l): fix idempotent when ceilometer_database_type == "gnocchi"
# NOTE(vbel): bootstrapping of mysql db for ceilometer is idempotent
- include: bootstrap_service.yml
when: ((ceilometer_database_type == "mongodb" and mongodb_ceilometer_database.changed)
or (ceilometer_database_type == "mysql" and mysql_ceilometer_database.changed )
or ceilometer_database_type == "gnocchi")