From c4e6c8ce300c3d9b959a64f854b24bbf7f120d03 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Thu, 28 Jun 2018 16:40:08 +0100 Subject: [PATCH] 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 'rally_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 'rally_galera_address' which has been used for a long time, but never documented. A bunch of unused variables have also been removed. Change-Id: Ifb89e35e3acaef33ce4ce24b3f5affc6c4e8e494 --- defaults/main.yml | 2 ++ tasks/rally_db_setup.yml | 26 ++++++++++++++++++++++++++ tests/os_rally-overrides.yml | 2 -- tests/test-install-rally.yml | 27 --------------------------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 97fa541..003ba86 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -46,6 +46,8 @@ rally_venv_download: "{{ not rally_developer_mode | bool }}" rally_venv_download_url: http://127.0.0.1/venvs/untagged/ubuntu/rally.tgz # Database vars +rally_db_setup_host: "{{ ('galera_all' in groups) | ternary(groups['galera_all'][0], 'localhost') }}" +rally_galera_address: "{{ galera_address | default('127.0.0.1') }}" rally_galera_database: rally rally_galera_user: rally rally_database_connection_string: mysql+pymysql://{{ rally_galera_user }}:{{ rally_galera_password }}@{{ rally_galera_address }}/{{ rally_galera_database }}?charset=utf8 diff --git a/tasks/rally_db_setup.yml b/tasks/rally_db_setup.yml index e1312d4..bae3b13 100644 --- a/tasks/rally_db_setup.yml +++ b/tasks/rally_db_setup.yml @@ -13,6 +13,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: "{{ rally_galera_address }}" + name: "{{ rally_galera_database }}" + state: "present" + delegate_to: "{{ rally_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: "{{ rally_galera_address }}" + name: "{{ rally_galera_user }}" + password: "{{ rally_galera_password }}" + host: "{{ item }}" + state: "present" + priv: "{{ rally_galera_database }}.*:ALL" + delegate_to: "{{ rally_db_setup_host }}" + with_items: + - "localhost" + - "%" + no_log: True + - name: Check for db command: "{{ rally_bin }}/rally deployment list" changed_when: false diff --git a/tests/os_rally-overrides.yml b/tests/os_rally-overrides.yml index 5e8f219..8573f78 100644 --- a/tests/os_rally-overrides.yml +++ b/tests/os_rally-overrides.yml @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -rally_galera_address: "{{ hostvars[groups['galera_all'][0]]['ansible_host'] }}" -rally_galera_database: rally rally_galera_password: "SuperSecrete" rally_venv_tag: "testing" rally_venv_download: False diff --git a/tests/test-install-rally.yml b/tests/test-install-rally.yml index 1c79b78..e1c2ddc 100644 --- a/tests/test-install-rally.yml +++ b/tests/test-install-rally.yml @@ -17,33 +17,6 @@ hosts: utility_all user: root gather_facts: true - pre_tasks: - - name: Create DB for service - mysql_db: - login_user: "root" - login_password: "secrete" - login_host: "localhost" - name: "{{ rally_galera_database }}" - state: "present" - delegate_to: "10.100.100.2" - when: inventory_hostname == groups['utility_all'][0] - no_log: true - - name: Grant access to the DB for the service - mysql_user: - login_user: "root" - login_password: "secrete" - login_host: "localhost" - name: "{{ rally_galera_database }}" - password: "{{ rally_galera_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ rally_galera_database }}.*:ALL" - with_items: - - "localhost" - - "%" - delegate_to: "10.100.100.2" - when: inventory_hostname == groups['utility_all'][0] - no_log: true roles: - role: "os_rally" vars_files: