Move database creation into role

There is no record for why we implement the database creation outside
of the role in the playbook, when we could do it inside the role.

Implementing it inside the role allows us to reduce the quantity of
group_vars duplicated from the role, and allows us to better document
the required variables in the role. The delegation can still be done
as it is done in the playbook too.

In this patch we implement a new variable called 'monasca_db_setup_host'
which is used in the role to allow delegation of the database setup
task to any host, but defaults to the first member of the galera_all
host group. We also document the variable 'monasca_galera_address' which
has been used for a long time, but never documented. A bunch of unused
variables have also been removed.

Change-Id: I42fe26054aec078a7a7ef66c20416af2cfb65811
This commit is contained in:
Jesse Pretorius 2018-06-28 16:24:25 +01:00
parent 43b0f56d24
commit 356317735b
6 changed files with 36 additions and 21 deletions

View File

@ -67,6 +67,8 @@ monasca_system_comment: monasca system user
monasca_system_user_home: "/var/lib/{{ monasca_system_user_name }}"
## DB info
magnum_db_setup_host: "{{ ('galera_all' in groups) | ternary(groups['galera_all'][0], 'localhost') }}"
magnum_galera_address: "{{ galera_address | default('127.0.0.1') }}"
monasca_galera_database: monasca
monasca_galera_user: monasca

View File

@ -20,7 +20,3 @@ influxdb_port: 8086
zookeeper_hosts: "{% for host in groups['monasca_zookeeper'] %}{{ hostvars[host]['ansible_host'] }}:{{ zookeeper_client_port }}{% if not loop.last %},{% endif %}{% endfor %}"
kafka_hosts: "{% for host in groups['monasca_kafka'] %}{{ hostvars[host]['ansible_host'] }}:{{ kafka_port }}{% if not loop.last %},{% endif %}{% endfor %}"
monasca_galera_user: monasca
monasca_galera_database: monasca
monasca_galera_address: "{{ galera_address }}"

View File

@ -20,39 +20,36 @@
hosts: monasca_all
gather_facts: "{{ gather_facts | default(True) }}"
user: root
environment: "{{ deployment_environment_variables | default({}) }}"
tags:
- monasca
pre_tasks:
- include: common-tasks/os-lxc-container-setup.yml
static: no
- include: common-tasks/os-log-dir-setup.yml
vars:
log_dirs:
- src: "/openstack/log/{{ inventory_hostname }}-monasca"
dest: "/var/log/monasca"
- include: common-tasks/mysql-db-user.yml
vars:
user_name: "{{ monasca_galera_user }}"
password: "{{ monasca_container_mysql_password }}"
login_host: "{{ monasca_galera_address }}"
db_name: "{{ monasca_galera_database }}"
when: inventory_hostname == groups['monasca_all'][0]
- include: common-tasks/package-cache-proxy.yml
roles:
- role: "os_monasca"
monasca_thresh_git_repo: "{{ openstack_repo_git_url }}/monasca-thresh"
monasca_common_git_repo: "{{ openstack_repo_git_url }}/monasca-common"
- role: "openstack_openrc"
tags:
- openrc
- role: "rsyslog_client"
rsyslog_client_log_rotate_file: monasca_log_rotate
rsyslog_client_log_dir: "/var/log/monasca"
rsyslog_client_config_name: "99-monasca-rsyslog-client.conf"
tags:
- rsyslog
- role: "system_crontab_coordination"
tags:
- crontab
vars:
is_metal: "{{ properties.is_metal|default(false) }}"
tags:
- monasca

View File

@ -11,6 +11,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Create DB for service
mysql_db:
login_user: "{{ galera_root_user }}"
login_password: "{{ galera_root_password }}"
login_host: "{{ monasca_galera_address }}"
name: "{{ monasca_galera_database }}"
state: "present"
delegate_to: "{{ monasca_db_setup_host }}"
no_log: True
- name: Grant access to the DB for the service
mysql_user:
login_user: "{{ galera_root_user }}"
login_password: "{{ galera_root_password }}"
login_host: "{{ monasca_galera_address }}"
name: "{{ monasca_galera_user }}"
password: "{{ monasca_container_mysql_password }}"
host: "{{ item }}"
state: "present"
priv: "{{ monasca_galera_database }}.*:ALL"
delegate_to: "{{ monasca_db_setup_host }}"
with_items:
- "localhost"
- "%"
no_log: True
- name: Copy mysql schema script to host
template:
dest: "/opt/mon_mysql.sql"

View File

@ -23,8 +23,6 @@ monasca_venv_tag: "testing"
monasca_developer_mode: true
monasca_service_password: "secrete"
monasca_galera_address: "{{ test_galera_host }}"
monasca_galera_database: monasca
monasca_galera_user: monasca
monasca_service_port: 8070
monasca_service_publicuri: "http://{{ test_monasca_host }}:{{ monasca_service_port }}"
monasca_service_publicurl: "{{ monasca_service_publicuri }}/v2.0"

View File

@ -21,10 +21,6 @@
remote_user: root
become: true
gather_facts: true
pre_tasks:
- include: common/create-grant-db.yml
db_name: "{{ monasca_galera_database }}"
db_password: "{{ monasca_container_mysql_password }}"
roles:
- role: "os_monasca"
vars_files: