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 'nova_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 nova_galera_address which
has been used for a long time, but never documented.

Change-Id: I7f977b2c24dcd20a4a7e8d32c13fb6c66127ce9c
This commit is contained in:
Jesse Pretorius 2018-06-01 18:15:17 +01:00
parent 4d02b6927b
commit 3048970324
3 changed files with 63 additions and 2 deletions

View File

@ -77,6 +77,8 @@ nova_lock_path: "/var/lock/nova"
# nova_system_group_gid = <GID>
## Database info
nova_db_setup_host: "{{ ('galera_all' in groups) | ternary(groups['galera_all'][0], 'localhost') }}"
nova_galera_address: "{{ galera_address | default('127.0.0.1') }}"
nova_galera_user: nova
nova_galera_database: nova
nova_db_max_overflow: 10
@ -88,6 +90,7 @@ nova_galera_use_ssl: "{{ galera_use_ssl | default(False) }}"
nova_galera_ssl_ca_cert: "{{ galera_ssl_ca_cert | default('/etc/ssl/certs/galera-ca.pem') }}"
## DB API
nova_api_galera_address: "{{ nova_galera_address }}"
nova_api_galera_user: nova_api
nova_api_galera_database: nova_api
nova_api_db_max_overflow: 10

View File

@ -1,9 +1,13 @@
.. code-block:: yaml
- name: Installation and setup of Neutron
hosts: neutron_all
- name: Installation and setup of Nova
hosts: nova_all
user: root
roles:
- { role: "os_neutron", tags: [ "os-neutron" ] }
vars:
neutron_galera_address: "{{ internal_lb_vip_address }}"
galera_root_user: root
vars_prompt:
- name: "galera_root_password"
prompt: "What is galera_root_password?"

View File

@ -13,6 +13,60 @@
# 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: "{{ nova_galera_address }}"
name: "{{ item }}"
state: "present"
delegate_to: "{{ nova_db_setup_host }}"
no_log: True
with_items:
- "{{ nova_galera_database }}"
- "{{ nova_api_galera_database }}"
- name: Grant access to DB's for the services
mysql_user:
login_user: "{{ galera_root_user }}"
login_password: "{{ galera_root_password }}"
login_host: "{{ nova_galera_address }}"
name: "{{ item['name'] }}"
password: "{{ item['password'] }}"
host: "{{ item['host'] }}"
state: "present"
priv: "{{ item['database'] }}.*:ALL"
append_privs: "{{ db_append_privs | default(omit) }}"
delegate_to: "{{ nova_db_setup_host }}"
with_items:
- name: "nova_galera_user"
password: "nova_container_mysql_password"
host: "localhost"
database: "nova_galera_database"
- name: "nova_galera_user"
password: "nova_container_mysql_password"
host: "%"
database: "nova_galera_database"
- name: "nova_api_galera_user"
password: "nova_api_container_mysql_password"
host: "localhost"
database: "nova_api_galera_database"
- name: "nova_api_galera_user"
password: "nova_api_container_mysql_password"
host: "%"
database: "nova_api_galera_database"
- name: "nova_api_galera_user"
password: "nova_api_container_mysql_password"
host: "localhost"
database: "nova_cell0_database"
db_append_privs: "yes"
- name: "nova_api_galera_user"
password: "nova_api_container_mysql_password"
host: "%"
database: "nova_cell0_database"
db_append_privs: "yes"
no_log: True
- name: Synchronize the nova API DB schema
command: "{{ nova_bin }}/nova-manage api_db sync"
become: yes