diff --git a/defaults/main.yml b/defaults/main.yml index e90dbe9..a45cda4 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -50,6 +50,8 @@ watcher_system_comment: watcher system user watcher_system_user_home: "/var/lib/{{ watcher_system_user_name }}" ## DB +watcher_db_setup_host: "{{ ('galera_all' in groups) | ternary(groups['galera_all'][0], 'localhost') }}" +watcher_galera_address: "{{ galera_address | default('127.0.0.1') }}" watcher_galera_user: watcher watcher_galera_database: watcher diff --git a/tasks/watcher_db_setup.yml b/tasks/watcher_db_setup.yml index 32c99f7..259f5eb 100644 --- a/tasks/watcher_db_setup.yml +++ b/tasks/watcher_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: "{{ watcher_galera_address }}" + name: "{{ watcher_galera_database }}" + state: "present" + delegate_to: "{{ watcher_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: "{{ watcher_galera_address }}" + name: "{{ watcher_galera_user }}" + password: "{{ watcher_galera_password }}" + host: "{{ item }}" + state: "present" + priv: "{{ watcher_galera_database }}.*:ALL" + delegate_to: "{{ watcher_db_setup_host }}" + with_items: + - "localhost" + - "%" + no_log: True + - name: Perform a Watcher DB schema command: "{{ watcher_bin }}/watcher-db-manage --config-file /etc/watcher/watcher.conf create_schema" become: yes diff --git a/tests/test-vars.yml b/tests/os_watcher-overrides.yml similarity index 90% rename from tests/test-vars.yml rename to tests/os_watcher-overrides.yml index 336e0f1..2f5fecd 100644 --- a/tests/test-vars.yml +++ b/tests/os_watcher-overrides.yml @@ -14,9 +14,6 @@ # limitations under the License. watcher_developer_mode: True -watcher_galera_address: "{{ hostvars[groups['galera_all'][0]]['ansible_host'] }}" -watcher_galera_database: watcher -watcher_galera_user: watcher watcher_galera_password: "secrete" watcher_rabbitmq_port: "{{ rabbitmq_port }}" watcher_rabbitmq_servers: "{{ rabbitmq_servers }}" diff --git a/tests/test-install-watcher.yml b/tests/test-install-watcher.yml index dc4d5f6..01dcac2 100644 --- a/tests/test-install-watcher.yml +++ b/tests/test-install-watcher.yml @@ -30,12 +30,14 @@ - pkg-config - libvirt-dev when: inventory_hostname in groups['watcher_all'] + - name: Ensure rabbitmq vhost rabbitmq_vhost: name: "{{ watcher_rabbitmq_vhost }}" state: "present" delegate_to: "{{ hostvars[groups['rabbitmq_all'][0]]['ansible_host'] }}" when: inventory_hostname == groups['watcher_all'][0] + - name: Ensure rabbitmq user rabbitmq_user: user: "{{ watcher_rabbitmq_userid }}" @@ -48,35 +50,8 @@ delegate_to: "{{ hostvars[groups['rabbitmq_all'][0]]['ansible_host'] }}" when: inventory_hostname == groups['watcher_all'][0] no_log: true - - name: Create DB for service - mysql_db: - login_user: "{{ galera_root_user }}" - login_password: "{{ galera_root_password }}" - login_host: "{{ watcher_galera_address }}" - name: "{{ watcher_galera_database }}" - state: "present" - delegate_to: "{{ hostvars[groups['galera_all'][0]]['ansible_host'] }}" - when: inventory_hostname == groups['watcher_all'][0] - 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: "{{ watcher_galera_address }}" - name: "{{ watcher_galera_database }}" - password: "{{ watcher_galera_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ watcher_galera_database }}.*:ALL" - with_items: - - "localhost" - - "%" - delegate_to: "{{ hostvars[groups['rabbitmq_all'][0]]['ansible_host'] }}" - when: inventory_hostname == groups['watcher_all'][0] - no_log: true roles: - role: "os_watcher" vars_files: - common/test-vars.yml - - test-vars.yml