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 'blazar_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 blazar_galera_address which
has been used for a long time, but never documented. A bunch of unused
variables have also been removed.

Change-Id: Id500e2b2a5b981609becc883edd3d166f70103f4
This commit is contained in:
Jesse Pretorius 2018-06-12 19:59:24 +01:00
parent 07a663f4e5
commit 1976e84796
3 changed files with 32 additions and 16 deletions

View File

@ -54,12 +54,10 @@ blazar_system_comment: blazar system user
blazar_system_user_home: "/var/lib/{{ blazar_system_user_name }}"
## Database credentials
blazar_db_name: blazar
blazar_db_user: root
blazar_db_login_host: ""
blazar_db_login_user: ""
blazar_db_login_password: ""
blazar_db_user_password: ""
blazar_db_setup_host: "{{ ('galera_all' in groups) | ternary(groups['galera_all'][0], 'localhost') }}"
blazar_galera_address: "{{ galera_address | default('127.0.0.1') }}"
blazar_galera_database: blazar
blazar_galera_user: blazar
## Service Type and Data
blazar_service_region: RegionOne
@ -97,10 +95,6 @@ blazar_keystone_auth_plugin: password
blazar_service_in_ldap: false
## DB info
blazar_galera_database: blazar
blazar_galera_user: blazar
blazar_role_name: admin
blazar_bind_address: 0.0.0.0
blazar_service_port: 9800
@ -108,4 +102,4 @@ blazar_program_name: blazar-server
## Tunable overrides
blazar_blazar_api_paste_ini_overrides: {}
blazar_blazar_conf_overrides: {}
blazar_blazar_conf_overrides: {}

View File

@ -14,7 +14,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- name: create blazar database schema
- name: Create DB for service
mysql_db:
login_user: "{{ galera_root_user }}"
login_password: "{{ galera_root_password }}"
login_host: "{{ blazar_galera_address }}"
name: "{{ blazar_galera_database }}"
state: "present"
delegate_to: "{{ blazar_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: "{{ blazar_galera_address }}"
name: "{{ blazar_galera_user }}"
password: "{{ blazar_container_mysql_password }}"
host: "{{ item }}"
state: "present"
priv: "{{ blazar_galera_database }}.*:ALL"
delegate_to: "{{ blazar_db_setup_host }}"
with_items:
- "localhost"
- "%"
no_log: True
- name: Create blazar database schema
command: >
{{ blazar_bin }}/blazar-db-manage
--config-file {{ blazar_conf_dir }}/blazar.conf upgrade head

View File

@ -27,10 +27,6 @@
when:
- "groups['rabbitmq_all'] is defined"
- include: common/create-grant-db.yml
db_name: "{{ blazar_galera_database }}"
db_password: "{{ blazar_container_mysql_password }}"
roles:
- role: "os_blazar"
vars_files: