diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index 64fc60b0ea..b0e261022b 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -314,13 +314,19 @@ glance_backend_file: "{{ not enable_ceph | bool }}" glance_backend_ceph: "{{ enable_ceph }}" +####################### +# Ceilometer options +####################### +# Valid options are [ mongodb, mysql ] +ceilometer_database_type: "mongodb" + + ################################# # Cinder options ################################# cinder_backend_ceph: "{{ enable_ceph }}" - ####################### # Nova options ####################### diff --git a/ansible/roles/ceilometer/tasks/bootstrap.yml b/ansible/roles/ceilometer/tasks/bootstrap.yml index 13fd87f9b3..0e6f77fc21 100644 --- a/ansible/roles/ceilometer/tasks/bootstrap.yml +++ b/ansible/roles/ceilometer/tasks/bootstrap.yml @@ -1,10 +1,5 @@ --- -- name: Checking backend for ceilometer - local_action: fail msg="No backend enabled for ceilometer. Mongodb is the only supported one for now" - changed_when: false - when: enable_ceilometer | bool and not enable_mongodb | bool - -- name: Creating Ceilometer database +- name: Creating Ceilometer MongoDB database command: docker exec -t mongodb mongo --host {{ ceilometer_database_address }} --eval 'db = db.getSiblingDB("{{ ceilometer_database_name }}"); db.addUser({user':' "{{ ceilometer_database_user }}", pwd':' "{{ ceilometer_database_password}}", roles':' [ "readWrite", "dbAdmin" ]})' register: database run_once: true @@ -12,5 +7,45 @@ - "'already' not in database.stdout" - database.stdout.split()[4] != 'connecting' delegate_to: "{{ groups['mongodb'][0] }}" + when: + - ceilometer_database_type == "mongodb" + +- name: Creating Ceilometer mysql database + command: docker exec -t kolla_toolbox /usr/bin/ansible localhost + -m mysql_db + -a "login_host='{{ database_address }}' + login_port='{{ database_port }}' + login_user='{{ database_user }}' + login_password='{{ database_password }}' + name='{{ ceilometer_database_name }}'" + register: database + changed_when: "{{ database.stdout.find('localhost | SUCCESS => ') != -1 and + (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" + failed_when: database.stdout.split()[2] != 'SUCCESS' + run_once: True + delegate_to: "{{ groups['ceilometer-api'][0] }}" + when: + - ceilometer_database_type == "mysql" + +- name: Creating Ceilometer database user and setting permissions + command: docker exec -t kolla_toolbox /usr/bin/ansible localhost + -m mysql_user + -a "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'" + register: database_user_create + changed_when: "{{ database_user_create.stdout.find('localhost | SUCCESS => ') != -1 and + (database_user_create.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" + failed_when: database_user_create.stdout.split()[2] != 'SUCCESS' + run_once: True + delegate_to: "{{ groups['ceilometer-api'][0] }}" + when: + - ceilometer_database_type == "mysql" - include: bootstrap_service.yml diff --git a/ansible/roles/ceilometer/templates/ceilometer.conf.j2 b/ansible/roles/ceilometer/templates/ceilometer.conf.j2 index 3979f2c18c..6ffe3b476f 100644 --- a/ansible/roles/ceilometer/templates/ceilometer.conf.j2 +++ b/ansible/roles/ceilometer/templates/ceilometer.conf.j2 @@ -12,7 +12,11 @@ host = {{ hostvars[inventory_hostname]['ansible_' + api_interface]['ipv4']['addr [collector] [database] +{% if ceilometer_database_type == "mongodb" %} connection = mongodb://{{ ceilometer_database_user }}:{{ ceilometer_database_password }}@{{ ceilometer_database_address }}:{{ mongodb_port }}/{{ ceilometer_database_name }} +{% elif ceilometer_database_type == "mysql" %} +connection = mysql+pymysql://{{ ceilometer_database_user }}:{{ ceilometer_database_password }}@{{ ceilometer_database_address }}/{{ ceilometer_database_name }} +{% endif %} [keystone_authtoken] memcached_servers = {{ kolla_internal_fqdn }}:{{ memcached_port }} diff --git a/ansible/roles/prechecks/tasks/service_checks.yml b/ansible/roles/prechecks/tasks/service_checks.yml index 700f3a2760..b4e7ca99cd 100644 --- a/ansible/roles/prechecks/tasks/service_checks.yml +++ b/ansible/roles/prechecks/tasks/service_checks.yml @@ -57,7 +57,10 @@ - groups['neutron-dhcp-agent'] | length < 2 or groups['neutron-l3-agent'] | length < 2 -- name: Checking backend for ceilometer - local_action: fail msg="No backend enabled for ceilometer. Mongodb is the only supported one for now" +- name: Checking mongodb backend for ceilometer + local_action: fail msg="ceilometer_database_type set to 'mongodb' but mongodb is not enabled" changed_when: false - when: enable_ceilometer | bool and not enable_mongodb | bool + when: + - enable_ceilometer | bool + - not enable_mongodb | bool + - ceilometer_database_type == "mongodb" diff --git a/etc/kolla/globals.yml b/etc/kolla/globals.yml index c401e5142f..41c8f4fddc 100644 --- a/etc/kolla/globals.yml +++ b/etc/kolla/globals.yml @@ -173,6 +173,11 @@ kolla_internal_vip_address: "10.10.10.254" #glance_backend_file: "yes" #glance_backend_ceph: "no" +####################### +# Ceilometer options +####################### +# Valid options are [ mongodb, mysql ] +#ceilometer_database_type: "mongodb" ####################### # Cinder options diff --git a/releasenotes/notes/add-mysql-ceilometer-backend-9ffdc4c0495fb801.yaml b/releasenotes/notes/add-mysql-ceilometer-backend-9ffdc4c0495fb801.yaml new file mode 100644 index 0000000000..3625c49e12 --- /dev/null +++ b/releasenotes/notes/add-mysql-ceilometer-backend-9ffdc4c0495fb801.yaml @@ -0,0 +1,3 @@ +--- +features: + - Allow mysql to be used as a database for Ceilometer.