From 7233b45d2949796aa3132ba976db75acbac0348d Mon Sep 17 00:00:00 2001 From: Jeffrey Zhang Date: Wed, 28 Dec 2016 23:52:55 +0800 Subject: [PATCH] Refactor bootstrap.yml file Change-Id: I00d2dcb0895548ba169ab85764cf546c2214cbf5 --- ansible/library/kolla_toolbox.py | 121 +++++++++++++++++++ ansible/roles/aodh/tasks/bootstrap.yml | 51 ++++---- ansible/roles/barbican/tasks/bootstrap.yml | 51 ++++---- ansible/roles/ceilometer/tasks/bootstrap.yml | 62 +++++----- ansible/roles/cinder/tasks/bootstrap.yml | 51 ++++---- ansible/roles/cloudkitty/tasks/bootstrap.yml | 51 ++++---- ansible/roles/congress/tasks/bootstrap.yml | 51 ++++---- ansible/roles/glance/tasks/bootstrap.yml | 51 ++++---- ansible/roles/gnocchi/tasks/bootstrap.yml | 51 ++++---- ansible/roles/grafana/tasks/bootstrap.yml | 46 +++---- ansible/roles/heat/tasks/bootstrap.yml | 51 ++++---- ansible/roles/horizon/tasks/bootstrap.yml | 51 ++++---- ansible/roles/ironic/tasks/bootstrap.yml | 51 ++++---- ansible/roles/keystone/tasks/bootstrap.yml | 53 ++++---- ansible/roles/magnum/tasks/bootstrap.yml | 51 ++++---- ansible/roles/manila/tasks/bootstrap.yml | 51 ++++---- ansible/roles/mistral/tasks/bootstrap.yml | 51 ++++---- ansible/roles/murano/tasks/bootstrap.yml | 51 ++++---- ansible/roles/neutron/tasks/bootstrap.yml | 51 ++++---- ansible/roles/nova/tasks/bootstrap.yml | 100 +++++---------- ansible/roles/octavia/tasks/bootstrap.yml | 51 ++++---- ansible/roles/rally/tasks/bootstrap.yml | 51 ++++---- ansible/roles/sahara/tasks/bootstrap.yml | 51 ++++---- ansible/roles/senlin/tasks/bootstrap.yml | 51 ++++---- ansible/roles/solum/tasks/bootstrap.yml | 51 ++++---- ansible/roles/tacker/tasks/bootstrap.yml | 51 ++++---- ansible/roles/trove/tasks/bootstrap.yml | 51 ++++---- ansible/roles/watcher/tasks/bootstrap.yml | 51 ++++---- 28 files changed, 702 insertions(+), 853 deletions(-) create mode 100644 ansible/library/kolla_toolbox.py diff --git a/ansible/library/kolla_toolbox.py b/ansible/library/kolla_toolbox.py new file mode 100644 index 0000000000..1548995282 --- /dev/null +++ b/ansible/library/kolla_toolbox.py @@ -0,0 +1,121 @@ +#!/usr/bin/python + +# Copyright 2016 99cloud Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +DOCUMENTATION = ''' +--- +module: kolla_toolbox +short_description: > + Module for invoking ansible module in kolla_toolbox container. +description: + - A module targerting at invoking ansible module in kolla_toolbox + container as used by Kolla project. +options: + module_name: + description: + - The module name to invoke + required: True + type: str + module_args: + description: + - The module args use by the module + required: False + type: str or dict +author: Jeffrey Zhang +''' + +EXAMPLES = ''' +- hosts: controller + tasks: + - name: Ensure the direct absent + kolla_toolbox: + module_name: file + module_args: path=/tmp/a state=absent + - name: Create mysql database + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: 192.168.1.10 + login_user: root + login_password: admin + name: testdb +''' + + +import docker +import json +import re + + +JSON_REG = re.compile('^(?P\w+) \| (?P\w+)!? =>(?P.*)$', + re.MULTILINE | re.DOTALL) +NON_JSON_REG = re.compile(('^(?P\w+) \| (?P\w+)!? \| ' + 'rc=(?P\d+) >>\n(?P.*)\n$'), + re.MULTILINE | re.DOTALL) + + +def gen_commandline(params): + command = ['ansible', 'localhost'] + if params.get('module_name'): + command.extend(['-m', params.get('module_name')]) + if params.get('module_args'): + module_args = params.get('module_args') + if isinstance(module_args, dict): + module_args = ' '.join("{}='{}'".format(key, value) + for key, value in module_args.items()) + command.extend(['-a', module_args]) + return command + + +def main(): + specs = dict( + module_name=dict(type='str'), + module_args=dict(type='str') + ) + module = AnsibleModule(argument_spec=specs, bypass_checks=True) + client = docker.Client() + command_line = gen_commandline(module.params) + kolla_toolbox = client.containers(all=True, + filters=dict(name='kolla_toolbox')) + if not kolla_toolbox: + module.fail_json(msg='Can not find kolla_toolbox container in target') + kolla_toolbox = kolla_toolbox[0] + if kolla_toolbox['State'] != 'running': + module.fail_json(msg='kolla_toolbox container is not running') + + job = client.exec_create(kolla_toolbox, command_line) + output = client.exec_start(job) + + for exp in [JSON_REG, NON_JSON_REG]: + m = exp.match(output) + if m: + inner_output = m.groupdict().get('stdout') + break + else: + module.fail_json( + msg='Can not parse the inner module output: %s' % output) + + ret = dict() + try: + ret = json.loads(inner_output) + except ValueError: + ret['stdout'] = inner_output + + module.exit_json(**ret) + + +from ansible.module_utils.basic import * # noqa +if __name__ == "__main__": + main() diff --git a/ansible/roles/aodh/tasks/bootstrap.yml b/ansible/roles/aodh/tasks/bootstrap.yml index e532e899d9..7c34e9397b 100644 --- a/ansible/roles/aodh/tasks/bootstrap.yml +++ b/ansible/roles/aodh/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating aodh 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='{{ aodh_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ aodh_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['aodh-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating aodh 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='{{ aodh_database_name }}' - password='{{ aodh_database_password }}' - host='%' - priv='{{ aodh_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ aodh_database_name }}" + password: "{{ aodh_database_password }}" + host: "%" + priv: "{{ aodh_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['aodh-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/barbican/tasks/bootstrap.yml b/ansible/roles/barbican/tasks/bootstrap.yml index b37ae86428..a2775dcfda 100644 --- a/ansible/roles/barbican/tasks/bootstrap.yml +++ b/ansible/roles/barbican/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating barbican 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='{{ barbican_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ barbican_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['barbican-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating barbican 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='{{ barbican_database_name }}' - password='{{ barbican_database_password }}' - host='%' - priv='{{ barbican_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ barbican_database_name }}" + password: "{{ barbican_database_password }}" + host: "%" + priv: "{{ barbican_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['barbican-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/ceilometer/tasks/bootstrap.yml b/ansible/roles/ceilometer/tasks/bootstrap.yml index 7078709ed6..31085c8533 100644 --- a/ansible/roles/ceilometer/tasks/bootstrap.yml +++ b/ansible/roles/ceilometer/tasks/bootstrap.yml @@ -11,13 +11,14 @@ - ceilometer_database_type == "mongodb" - name: Checking Ceilometer mysql database - command: docker exec -t kolla_toolbox /usr/bin/ansible localhost - -m mysql_db - -a "login_host='{{ ceilometer_database_mysql_address }}' - login_port='{{ ceilometer_database_port }}' - login_user='{{ ceilometer_database_user }}' - login_password='{{ ceilometer_database_password }}' - name='{{ ceilometer_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ ceilometer_database_mysql_address }}" + login_port: "{{ ceilometer_database_port }}" + login_user: "{{ ceilomter_database_user }}" + login_password: "{{ ceilometer_database_password }}" + name: "{{ ceilometer_database_name }}" register: mysql_access failed_when: False changed_when: False @@ -26,17 +27,15 @@ - ceilometer_database_type == "mysql" - name: Creating Ceilometer mysql database - command: docker exec -t kolla_toolbox /usr/bin/ansible localhost - -m mysql_db - -a "login_host='{{ ceilometer_database_mysql_address }}' - login_port='{{ ceilometer_database_port }}' - login_user='{{ database_user }}' - login_password='{{ database_password }}' - name='{{ ceilometer_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ ceilometer_database_name }}" register: mysql_ceilometer_database - changed_when: "{{ mysql_ceilometer_database.stdout.find('localhost | SUCCESS => ') != -1 and - (mysql_ceilometer_database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - failed_when: mysql_ceilometer_database.stdout.split()[2] != 'SUCCESS' run_once: True delegate_to: "{{ groups['ceilometer-api'][0] }}" when: @@ -44,21 +43,18 @@ - "'FAILED' in mysql_access.stdout" - name: Creating Ceilometer database user and setting permissions - command: docker exec -t kolla_toolbox /usr/bin/ansible localhost - -m mysql_user - -a "login_host='{{ ceilometer_database_mysql_address }}' - login_port='{{ ceilometer_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' + kolla_toolbox: + module_name: mysql_user + module_args: + 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" run_once: True delegate_to: "{{ groups['ceilometer-api'][0] }}" when: @@ -69,5 +65,5 @@ # NOTE(vbel): bootstrapping of mysql db for ceilometer is idempotent - include: bootstrap_service.yml when: ((ceilometer_database_type == "mongodb" and mongodb_ceilometer_database.changed) - or ceilometer_database_type == "mysql" + or (ceilometer_database_type == "mysql" and mysql_ceilometer_database.changed ) or ceilometer_database_type == "gnocchi") diff --git a/ansible/roles/cinder/tasks/bootstrap.yml b/ansible/roles/cinder/tasks/bootstrap.yml index f2a62dc141..5a38351fc4 100644 --- a/ansible/roles/cinder/tasks/bootstrap.yml +++ b/ansible/roles/cinder/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Cinder 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='{{ cinder_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ cinder_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['cinder-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Cinder 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='{{ cinder_database_name }}' - password='{{ cinder_database_password }}' - host='%' - priv='{{ cinder_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ cinder_database_name }}" + password: "{{ cinder_database_password }}" + host: "%" + priv: "{{ cinder_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['cinder-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/cloudkitty/tasks/bootstrap.yml b/ansible/roles/cloudkitty/tasks/bootstrap.yml index 4e9de7a173..47f85002eb 100644 --- a/ansible/roles/cloudkitty/tasks/bootstrap.yml +++ b/ansible/roles/cloudkitty/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Cloudkitty 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='{{ cloudkitty_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ cloudkitty_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['cloudkitty-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Cloudkitty 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='{{ cloudkitty_database_name }}' - password='{{ cloudkitty_database_password }}' - host='%' - priv='{{ cloudkitty_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ cloudkitty_database_name }}" + password: "{{ cloudkitty_database_password }}" + host: "%" + priv: "{{ cloudkitty_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['cloudkitty-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/congress/tasks/bootstrap.yml b/ansible/roles/congress/tasks/bootstrap.yml index 3049594160..86b49fd8e2 100644 --- a/ansible/roles/congress/tasks/bootstrap.yml +++ b/ansible/roles/congress/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating congress 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='{{ congress_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ congress_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['congress-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating congress 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='{{ congress_database_name }}' - password='{{ congress_database_password }}' - host='%' - priv='{{ congress_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ congress_database_name }}" + password: "{{ congress_database_password }}" + host: "%" + priv: "{{ congress_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['congress-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/glance/tasks/bootstrap.yml b/ansible/roles/glance/tasks/bootstrap.yml index 10d650d926..cafdfd4cf8 100644 --- a/ansible/roles/glance/tasks/bootstrap.yml +++ b/ansible/roles/glance/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Glance 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='{{ glance_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ glance_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['glance-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Glance 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='{{ glance_database_name }}' - password='{{ glance_database_password }}' - host='%' - priv='{{ glance_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ glance_database_name }}" + password: "{{ glance_database_password }}" + host: "%" + priv: "{{ glance_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['glance-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/gnocchi/tasks/bootstrap.yml b/ansible/roles/gnocchi/tasks/bootstrap.yml index 70611b85d5..671dfac5ed 100644 --- a/ansible/roles/gnocchi/tasks/bootstrap.yml +++ b/ansible/roles/gnocchi/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating gnocchi 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='{{ gnocchi_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ gnocchi_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['gnocchi-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating gnocchi 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='{{ gnocchi_database_name }}' - password='{{ gnocchi_database_password }}' - host='%' - priv='{{ gnocchi_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ gnocchi_database_name }}" + password: "{{ gnocchi_database_password }}" + host: "%" + priv: "{{ gnocchi_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['gnocchi-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/grafana/tasks/bootstrap.yml b/ansible/roles/grafana/tasks/bootstrap.yml index 492b516e20..dba3614aec 100644 --- a/ansible/roles/grafana/tasks/bootstrap.yml +++ b/ansible/roles/grafana/tasks/bootstrap.yml @@ -1,38 +1,24 @@ --- - name: Creating grafana 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='{{ grafana_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' + mysql_db: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ grafana_database_name }}" run_once: True delegate_to: "{{ groups['grafana'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating grafana 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='{{ grafana_database_name }}' - password='{{ grafana_database_password }}' - host='%' - priv='{{ grafana_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' + mysql_user: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ grafana_database_name }}" + password: "{{ grafana_database_password }}" + host: "%" + priv: "{{ grafana_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['grafana'][0] }}" diff --git a/ansible/roles/heat/tasks/bootstrap.yml b/ansible/roles/heat/tasks/bootstrap.yml index 50c74920b2..2895989b26 100644 --- a/ansible/roles/heat/tasks/bootstrap.yml +++ b/ansible/roles/heat/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Heat 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='{{ heat_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ heat_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['heat-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Heat 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='{{ heat_database_name }}' - password='{{ heat_database_password }}' - host='%' - priv='{{ heat_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ heat_database_name }}" + password: "{{ heat_database_password }}" + host: "%" + priv: "{{ heat_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['heat-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/horizon/tasks/bootstrap.yml b/ansible/roles/horizon/tasks/bootstrap.yml index 6e6127495a..ae92474574 100644 --- a/ansible/roles/horizon/tasks/bootstrap.yml +++ b/ansible/roles/horizon/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Horizon 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='{{ horizon_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ horizon_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['horizon'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Horizon 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='{{ horizon_database_name }}' - password='{{ horizon_database_password }}' - host='%' - priv='{{ horizon_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ horizon_database_name }}" + password: "{{ horizon_database_password }}" + host: "%" + priv: "{{ horizon_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['horizon'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/ironic/tasks/bootstrap.yml b/ansible/roles/ironic/tasks/bootstrap.yml index 54eecc0f0e..bbeba8e5f9 100644 --- a/ansible/roles/ironic/tasks/bootstrap.yml +++ b/ansible/roles/ironic/tasks/bootstrap.yml @@ -1,44 +1,35 @@ --- - name: Creating Ironic 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='{{ ironic_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ ironic_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['ironic-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Ironic 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='{{ ironic_database_name }}' - password='{{ ironic_database_password }}' - host='%' - priv='{{ ironic_database_name }}.*:ALL' - append_privs='yes'" - register: database_user_create - changed_when: "{{ database.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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ ironic_database_name }}" + password: "{{ ironic_database_password }}" + host: "%" + priv: "{{ ironic_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['ironic-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed - name: Running Ironic-PXE bootstrap container kolla_docker: diff --git a/ansible/roles/keystone/tasks/bootstrap.yml b/ansible/roles/keystone/tasks/bootstrap.yml index 301933e47c..1ac7b6aeca 100644 --- a/ansible/roles/keystone/tasks/bootstrap.yml +++ b/ansible/roles/keystone/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- -- name: Creating Keystone 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='{{ keystone_database_name }}'" +- name: Creating keystone database + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ keystone_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['keystone'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Keystone 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='{{ keystone_database_name }}' - password='{{ keystone_database_password }}' - host='%' - priv='{{ keystone_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ keystone_database_name }}" + password: "{{ keystone_database_password }}" + host: "%" + priv: "{{ keystone_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['keystone'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/magnum/tasks/bootstrap.yml b/ansible/roles/magnum/tasks/bootstrap.yml index af9d640fbe..87f5268200 100644 --- a/ansible/roles/magnum/tasks/bootstrap.yml +++ b/ansible/roles/magnum/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Magnum 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='{{ magnum_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ magnum_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['magnum-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Magnum 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='{{ magnum_database_name }}' - password='{{ magnum_database_password }}' - host='%' - priv='{{ magnum_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ magnum_database_name }}" + password: "{{ magnum_database_password }}" + host: "%" + priv: "{{ magnum_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['magnum-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/manila/tasks/bootstrap.yml b/ansible/roles/manila/tasks/bootstrap.yml index 0d51963b0e..58051d1c66 100644 --- a/ansible/roles/manila/tasks/bootstrap.yml +++ b/ansible/roles/manila/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Manila 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='{{ manila_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ manila_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['manila-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Manila 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='{{ manila_database_name }}' - password='{{ manila_database_password }}' - host='%' - priv='{{ manila_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ manila_database_name }}" + password: "{{ manila_database_password }}" + host: "%" + priv: "{{ manila_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['manila-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/mistral/tasks/bootstrap.yml b/ansible/roles/mistral/tasks/bootstrap.yml index 10f8a7773f..0623cad26a 100644 --- a/ansible/roles/mistral/tasks/bootstrap.yml +++ b/ansible/roles/mistral/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Mistral 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='{{ mistral_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ mistral_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['mistral-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Mistral 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='{{ mistral_database_name }}' - password='{{ mistral_database_password }}' - host='%' - priv='{{ mistral_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ mistral_database_name }}" + password: "{{ mistral_database_password }}" + host: "%" + priv: "{{ mistral_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['mistral-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/murano/tasks/bootstrap.yml b/ansible/roles/murano/tasks/bootstrap.yml index 931636ee82..800233c8a4 100644 --- a/ansible/roles/murano/tasks/bootstrap.yml +++ b/ansible/roles/murano/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Murano 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='{{ murano_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ murano_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['murano-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Murano 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='{{ murano_database_name }}' - password='{{ murano_database_password }}' - host='%' - priv='{{ murano_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ murano_database_name }}" + password: "{{ murano_database_password }}" + host: "%" + priv: "{{ murano_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['murano-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/neutron/tasks/bootstrap.yml b/ansible/roles/neutron/tasks/bootstrap.yml index 526743fb93..13d70b627c 100644 --- a/ansible/roles/neutron/tasks/bootstrap.yml +++ b/ansible/roles/neutron/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Neutron 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='{{ neutron_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ neutron_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['neutron-server'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Neutron 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='{{ neutron_database_name }}' - password='{{ neutron_database_password }}' - host='%' - priv='{{ neutron_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ neutron_database_name }}" + password: "{{ neutron_database_password }}" + host: "%" + priv: "{{ neutron_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['neutron-server'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/nova/tasks/bootstrap.yml b/ansible/roles/nova/tasks/bootstrap.yml index dd2222591e..adfd64a454 100644 --- a/ansible/roles/nova/tasks/bootstrap.yml +++ b/ansible/roles/nova/tasks/bootstrap.yml @@ -1,79 +1,41 @@ --- -- name: Creating Nova 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='{{ nova_database_name }}'" +- name: Creating Nova databases + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ item }}" 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['nova-api'][0] }}" + with_items: + - "{{ nova_database_name }}" + - "{{ nova_api_database_name }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - -- name: Creating Nova-api 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='{{ nova_api_database_name }}'" - register: database_api - changed_when: "{{ database_api.stdout.find('localhost | SUCCESS => ') != -1 and - (database_api.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - failed_when: database_api.stdout.split()[2] != 'SUCCESS' - run_once: True - delegate_to: "{{ groups['nova-api'][0] }}" - -- name: Reading json from variable - set_fact: - database_api_created: "{{ (database_api.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - -- name: Creating Nova 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='{{ nova_database_name }}' - password='{{ nova_database_password }}' - host='%' - priv='{{ nova_database_name }}.*:ALL' - append_privs='yes'" +- name: Creating Nova databases user and setting permissions + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ item.database_name }}" + password: "{{ item.database_password }}" + host: "%" + priv: "{{ item.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['nova-api'][0] }}" - -- name: Creating Nova-api 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='{{ nova_api_database_name }}' - password='{{ nova_api_database_password }}' - host='%' - priv='{{ nova_api_database_name }}.*:ALL' - append_privs='yes'" - register: database_api_user_create - changed_when: "{{ database_api_user_create.stdout.find('localhost | SUCCESS => ') != -1 and - (database_api_user_create.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - failed_when: database_api_user_create.stdout.split()[2] != 'SUCCESS' + with_items: + - database_name: "{{ nova_database_name }}" + database_password: "{{ nova_database_password }}" + - database_name: "{{ nova_api_database_name }}" + database_password: "{{ nova_api_database_password }}" run_once: True delegate_to: "{{ groups['nova-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/octavia/tasks/bootstrap.yml b/ansible/roles/octavia/tasks/bootstrap.yml index 5676e387a6..787c647bee 100644 --- a/ansible/roles/octavia/tasks/bootstrap.yml +++ b/ansible/roles/octavia/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Octavia 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='{{ octavia_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ octavia_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['octavia-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Octavia 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='{{ octavia_database_name }}' - password='{{ octavia_database_password }}' - host='%' - priv='{{ octavia_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ octavia_database_name }}" + password: "{{ octavia_database_password }}" + host: "%" + priv: "{{ octavia_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['octavia-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/rally/tasks/bootstrap.yml b/ansible/roles/rally/tasks/bootstrap.yml index 9875c3e57b..37e5bfa5d9 100644 --- a/ansible/roles/rally/tasks/bootstrap.yml +++ b/ansible/roles/rally/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating rally 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='{{ rally_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ rally_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['rally'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating rally 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='{{ rally_database_name }}' - password='{{ rally_database_password }}' - host='%' - priv='{{ rally_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ rally_database_name }}" + password: "{{ rally_database_password }}" + host: "%" + priv: "{{ rally_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['rally'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/sahara/tasks/bootstrap.yml b/ansible/roles/sahara/tasks/bootstrap.yml index 6e98f125b8..8a668fc83f 100644 --- a/ansible/roles/sahara/tasks/bootstrap.yml +++ b/ansible/roles/sahara/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating sahara 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='{{ sahara_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ sahara_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['sahara-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating sahara 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='{{ sahara_database_name }}' - password='{{ sahara_database_password }}' - host='%' - priv='{{ sahara_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ sahara_database_name }}" + password: "{{ sahara_database_password }}" + host: "%" + priv: "{{ sahara_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['sahara-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/senlin/tasks/bootstrap.yml b/ansible/roles/senlin/tasks/bootstrap.yml index 95a599b179..6599961ac7 100644 --- a/ansible/roles/senlin/tasks/bootstrap.yml +++ b/ansible/roles/senlin/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Senlin 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='{{ senlin_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ senlin_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['senlin-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Senlin 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='{{ senlin_database_name }}' - password='{{ senlin_database_password }}' - host='%' - priv='{{ senlin_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ senlin_database_name }}" + password: "{{ senlin_database_password }}" + host: "%" + priv: "{{ senlin_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['senlin-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/solum/tasks/bootstrap.yml b/ansible/roles/solum/tasks/bootstrap.yml index 3d1ff9e15e..cf3063abc5 100644 --- a/ansible/roles/solum/tasks/bootstrap.yml +++ b/ansible/roles/solum/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Solum 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='{{ solum_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ solum_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['solum-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Solum 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='{{ solum_database_name }}' - password='{{ solum_database_password }}' - host='%' - priv='{{ solum_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ solum_database_name }}" + password: "{{ solum_database_password }}" + host: "%" + priv: "{{ solum_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['solum-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/tacker/tasks/bootstrap.yml b/ansible/roles/tacker/tasks/bootstrap.yml index 5937c2add8..7a8f4aa868 100644 --- a/ansible/roles/tacker/tasks/bootstrap.yml +++ b/ansible/roles/tacker/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating tacker 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='{{ tacker_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ tacker_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['tacker'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating tacker 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='{{ tacker_database_name }}' - password='{{ tacker_database_password }}' - host='%' - priv='{{ tacker_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ tacker_database_name }}" + password: "{{ tacker_database_password }}" + host: "%" + priv: "{{ tacker_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['tacker'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/trove/tasks/bootstrap.yml b/ansible/roles/trove/tasks/bootstrap.yml index 56f6bf12c1..6764c6ea41 100644 --- a/ansible/roles/trove/tasks/bootstrap.yml +++ b/ansible/roles/trove/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating trove 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='{{ trove_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ trove_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['trove-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating trove 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='{{ trove_database_name }}' - password='{{ trove_database_password }}' - host='%' - priv='{{ trove_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ trove_database_name }}" + password: "{{ trove_database_password }}" + host: "%" + priv: "{{ trove_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['trove-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed diff --git a/ansible/roles/watcher/tasks/bootstrap.yml b/ansible/roles/watcher/tasks/bootstrap.yml index fa63250e36..58da9f296c 100644 --- a/ansible/roles/watcher/tasks/bootstrap.yml +++ b/ansible/roles/watcher/tasks/bootstrap.yml @@ -1,41 +1,32 @@ --- - name: Creating Watcher 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='{{ watcher_database_name }}'" + kolla_toolbox: + module_name: mysql_db + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ wather_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['watcher-api'][0] }}" -- name: Reading json from variable - set_fact: - database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}" - - name: Creating Watcher 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='{{ watcher_database_name }}' - password='{{ watcher_database_password }}' - host='%' - priv='{{ watcher_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' + kolla_toolbox: + module_name: mysql_user + module_args: + login_host: "{{ database_address }}" + login_port: "{{ database_port }}" + login_user: "{{ database_user }}" + login_password: "{{ database_password }}" + name: "{{ wather_database_name }}" + password: "{{ wather_database_password }}" + host: "%" + priv: "{{ wather_database_name }}.*:ALL" + append_privs: "yes" run_once: True delegate_to: "{{ groups['watcher-api'][0] }}" - include: bootstrap_service.yml - when: database_created + when: database.changed