From 7f03b7fdc49ef4e77a8b7f67c2f2a76dfe4fe87e Mon Sep 17 00:00:00 2001 From: root Date: Thu, 11 Aug 2016 22:00:15 +0000 Subject: [PATCH] Added tasks in nova and neutron test yml files Moved Rabbitmq and DB tasks to generic files. This patch removes the redundant behaviour of the tasks such as Ensuring Rabbitmq hosts and user, creating db, granting access to db in the testing yml files. The patch makes it more generic and shifted the common tasks to separate files create-grant-db.yml and ensure-rabbitmq.yml Change-Id: Ibd94e1ebdce45b782ab447ca3db5068588a1e368 --- create-grant-db.yml | 38 +++++++++++++++ ensure-rabbitmq.yml | 32 +++++++++++++ setting-nodepool-variables.yml | 34 +++++++++++++ test-install-glance.yml | 50 ++++--------------- test-install-keystone.yml | 67 +++++--------------------- test-install-neutron.yml | 62 +++++------------------- test-install-nova.yml | 88 ++++++---------------------------- 7 files changed, 149 insertions(+), 222 deletions(-) create mode 100644 create-grant-db.yml create mode 100644 ensure-rabbitmq.yml create mode 100644 setting-nodepool-variables.yml diff --git a/create-grant-db.yml b/create-grant-db.yml new file mode 100644 index 00000000..377e9126 --- /dev/null +++ b/create-grant-db.yml @@ -0,0 +1,38 @@ +--- +# Copyright 2015, Rackspace US, 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. +- name: Create DB for service + mysql_db: + login_user: "root" + login_password: "secrete" + login_host: "localhost" + name: "{{ db_name }}" + state: "present" + delegate_to: "{{ groups['galera_all'][0] }}" + when: inventory_hostname == "{{ host_name }}" +- name: Grant access to the DB for the service + mysql_user: + login_user: "root" + login_password: "secrete" + login_host: "localhost" + name: "{{ db_name }}" + password: "{{ db_password }}" + host: "{{ item }}" + state: "present" + priv: "{{ db_name }}.*:ALL" + with_items: + - "localhost" + - "%" + delegate_to: "{{ groups['galera_all'][0] }}" + when: inventory_hostname == "{{ host_name }}" diff --git a/ensure-rabbitmq.yml b/ensure-rabbitmq.yml new file mode 100644 index 00000000..1feef0aa --- /dev/null +++ b/ensure-rabbitmq.yml @@ -0,0 +1,32 @@ +--- +# Copyright 2015, Rackspace US, 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. +- name: Ensure rabbitmq vhost + rabbitmq_vhost: + name: "{{ vhost_name }}" + state: "present" + delegate_to: "{{ groups['rabbitmq_all'][0] }}" + when: inventory_hostname == "{{ host_name }}" +- name: Ensure rabbitmq user + rabbitmq_user: + user: "{{ user_name }}" + password: "{{ user_password }}" + vhost: "{{ vhost_name }}" + configure_priv: ".*" + read_priv: ".*" + write_priv: ".*" + state: "present" + delegate_to: "{{ groups['rabbitmq_all'][0] }}" + when: inventory_hostname == "{{ host_name }}" + diff --git a/setting-nodepool-variables.yml b/setting-nodepool-variables.yml new file mode 100644 index 00000000..c6be5801 --- /dev/null +++ b/setting-nodepool-variables.yml @@ -0,0 +1,34 @@ +--- +# Copyright 2015, Rackspace US, 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. + +- name: Setting nodepool variables + hosts: all + gather_facts: false + tasks: + - name: Check if this is an OpenStack-CI nodepool instance + stat: + path: /etc/nodepool/provider + register: nodepool + delegate_to: localhost + - name: Determine the existing Ubuntu repo URL (only on OpenStack-CI) + shell: 'awk "/^deb .*ubuntu\/? {{ ansible_distribution_release }} main/ {print \$2; exit}" /etc/apt/sources.list' + register: ubuntu_repo_url + changed_when: false + when: ansible_pkg_mgr == 'apt' and nodepool.stat.exists == True + delegate_to: localhost + - name: Set Ubuntu Cloud Archive repo URL based on discovered information + set_fact: + uca_apt_repo_url: "{{ ubuntu_repo_url.stdout | netorigin }}/ubuntu-cloud-archive" + when: ansible_pkg_mgr == 'apt' and nodepool.stat.exists == True diff --git a/test-install-glance.yml b/test-install-glance.yml index ddf4b27c..cdf243de 100644 --- a/test-install-glance.yml +++ b/test-install-glance.yml @@ -18,47 +18,15 @@ user: root gather_facts: true pre_tasks: - - name: Ensure rabbitmq vhost - rabbitmq_vhost: - name: "{{ glance_rabbitmq_vhost }}" - state: "present" - delegate_to: "{{ groups['rabbitmq_all'][0] }}" - when: inventory_hostname == groups['glance_all'][0] - - name: Ensure rabbitmq user - rabbitmq_user: - user: "{{ glance_rabbitmq_userid }}" - password: "{{ glance_rabbitmq_password }}" - vhost: "{{ glance_rabbitmq_vhost }}" - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - state: "present" - delegate_to: "{{ groups['rabbitmq_all'][0] }}" - when: inventory_hostname == groups['glance_all'][0] - - name: Create DB for service - mysql_db: - login_user: "root" - login_password: "secrete" - login_host: "localhost" - name: "{{ glance_galera_database }}" - state: "present" - delegate_to: "{{ groups['galera_all'][0] }}" - when: inventory_hostname == groups['glance_all'][0] - - name: Grant access to the DB for the service - mysql_user: - login_user: "root" - login_password: "secrete" - login_host: "localhost" - name: "{{ glance_galera_database }}" - password: "{{ glance_container_mysql_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ glance_galera_database }}.*:ALL" - with_items: - - "localhost" - - "%" - delegate_to: "{{ groups['galera_all'][0] }}" - when: inventory_hostname == groups['glance_all'][0] + - include: ensure-rabbitmq.yml + vhost_name: "{{ glance_rabbitmq_vhost }}" + user_name: "{{ glance_rabbitmq_userid }}" + user_password: "{{ glance_rabbitmq_password }}" + host_name: groups['glance_all'][0] + - include: create-grant-db.yml + db_name: "{{ glance_galera_database }}" + db_password: "{{ glance_container_mysql_password }}" + host_name: groups['glance_all'][0] roles: - role: "{{ glance_rolename | default('os_glance') }}" vars_files: diff --git a/test-install-keystone.yml b/test-install-keystone.yml index 132a4309..3121f9cc 100644 --- a/test-install-keystone.yml +++ b/test-install-keystone.yml @@ -18,63 +18,18 @@ user: root gather_facts: true pre_tasks: - - name: Set keystone_messaging fact no rabbit + - name: Set keystone_messaging fact set_fact: - keystone_messaging_enabled: false - when: groups['rabbitmq_all'] is not defined - - name: Set keystone_messaging fact rabbit - set_fact: - keystone_messaging_enabled: true - when: groups['rabbitmq_all'] is defined - - name: Ensure rabbitmq vhost - rabbitmq_vhost: - name: "{{ keystone_rabbitmq_vhost }}" - state: "present" - delegate_to: "{{ groups['rabbitmq_all'][0] }}" - when: - - inventory_hostname == groups['keystone_all'][0] - - groups['rabbitmq_all'] is defined - - name: Ensure rabbitmq user - rabbitmq_user: - user: "{{ keystone_rabbitmq_userid }}" - password: "{{ keystone_rabbitmq_password }}" - vhost: "{{ keystone_rabbitmq_vhost }}" - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - state: "present" - delegate_to: "{{ groups['rabbitmq_all'][0] }}" - when: - - inventory_hostname == groups['keystone_all'][0] - - groups['rabbitmq_all'] is defined - - name: Create DB for service - mysql_db: - login_user: "root" - login_password: "secrete" - login_host: "localhost" - name: "{{ keystone_galera_database }}" - state: "present" - delegate_to: "{{ groups['galera_all'][0] }}" - when: inventory_hostname == groups['keystone_all'][0] - tags: - - mysql-db-setup - - name: Grant access to the DB for the service - mysql_user: - login_user: "{{ galera_root_user }}" - login_password: "{{ galera_root_password }}" - login_host: "localhost" - name: "{{ keystone_galera_database }}" - password: "{{ keystone_container_mysql_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ keystone_galera_database }}.*:ALL" - with_items: - - "localhost" - - "%" - delegate_to: "{{ groups['galera_all'][0] }}" - when: inventory_hostname == groups['keystone_all'][0] - tags: - - mysql-db-setup + keystone_messaging_enabled: "{{ groups['rabbitmq_all'] is defined }}" + - include: ensure-rabbitmq.yml + vhost_name: "{{ keystone_rabbitmq_vhost }}" + user_name: "{{ keystone_rabbitmq_userid }}" + user_password: "{{ keystone_rabbitmq_password }}" + host_name: groups['keystone_all'][0] + - include: create-grant-db.yml + db_name: "{{ keystone_galera_database }}" + db_password: "{{ keystone_container_mysql_password }}" + host_name: groups['keystone_all'][0] roles: - role: "{{ keystone_rolename | default('os_keystone') }}" vars_files: diff --git a/test-install-neutron.yml b/test-install-neutron.yml index 0450ee74..ab99983b 100644 --- a/test-install-neutron.yml +++ b/test-install-neutron.yml @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +- include: setting-nodepool-variables.yml + - name: Make /lib/modules accessible on neutron_agent containers hosts: neutron_agent user: root @@ -56,57 +58,15 @@ with_items: - libffi-dev when: inventory_hostname in groups['neutron_all'] - - name: Ensure rabbitmq vhost - rabbitmq_vhost: - name: "{{ neutron_rabbitmq_vhost }}" - state: "present" - delegate_to: "{{ groups['rabbitmq_all'][0] }}" - when: inventory_hostname == groups['neutron_all'][0] - tags: - - neutron-rabbitmq - - neutron-rabbitmq-vhost - - name: Ensure rabbitmq user - rabbitmq_user: - user: "{{ neutron_rabbitmq_userid }}" - password: "{{ neutron_rabbitmq_password }}" - vhost: "{{ neutron_rabbitmq_vhost }}" - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - state: "present" - delegate_to: "{{ groups['rabbitmq_all'][0] }}" - when: inventory_hostname == groups['neutron_all'][0] - tags: - - neutron-rabbitmq - - neutron-rabbitmq-user - - name: Create DB for service - mysql_db: - login_user: "root" - login_password: "secrete" - login_host: "localhost" - name: "{{ neutron_galera_database }}" - state: "present" - delegate_to: "{{ groups['galera_all'][0] }}" - when: inventory_hostname == groups['neutron_all'][0] - tags: - - mysql-db-setup - - name: Grant access to the DB for the service - mysql_user: - login_user: "root" - login_password: "secrete" - login_host: "localhost" - name: "{{ neutron_galera_database }}" - password: "{{ neutron_container_mysql_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ neutron_galera_database }}.*:ALL" - with_items: - - "localhost" - - "%" - delegate_to: "{{ groups['galera_all'][0] }}" - when: inventory_hostname == groups['neutron_all'][0] - tags: - - mysql-db-setup + - include: ensure-rabbitmq.yml + vhost_name: "{{ neutron_rabbitmq_vhost }}" + user_name: "{{ neutron_rabbitmq_userid }}" + user_password: "{{ neutron_rabbitmq_password }}" + host_name: groups['neutron_all'][0] + - include: create-grant-db.yml + db_name: "{{ neutron_galera_database }}" + db_password: "{{ neutron_container_mysql_password }}" + host_name: groups['neutron_all'][0] roles: - role: "{{ neutron_rolename | default('os_neutron') }}" vars_files: diff --git a/test-install-nova.yml b/test-install-nova.yml index b36ce4fb..0ce62a15 100644 --- a/test-install-nova.yml +++ b/test-install-nova.yml @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +- include: setting-nodepool-variables.yml + - name: Playbook for deploying nova hosts: nova_all user: root @@ -29,80 +31,18 @@ - libffi-dev - pkg-config - libvirt-dev - when: inventory_hostname in groups['nova_all'] - - name: Ensure rabbitmq vhost - rabbitmq_vhost: - name: "{{ nova_rabbitmq_vhost }}" - state: "present" - delegate_to: "{{ groups['rabbitmq_all'][0] }}" - when: inventory_hostname == groups['nova_all'][0] - tags: - - aodh-rabbitmq - - aodh-rabbitmq-vhost - - name: Ensure rabbitmq user - rabbitmq_user: - user: "{{ nova_rabbitmq_userid }}" - password: "{{ nova_rabbitmq_password }}" - vhost: "{{ nova_rabbitmq_vhost }}" - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - state: "present" - delegate_to: "{{ groups['rabbitmq_all'][0] }}" - when: inventory_hostname == groups['nova_all'][0] - tags: - - aodh-rabbitmq - - aodh-rabbitmq-user - - name: Create DB for service - mysql_db: - login_user: "root" - login_password: "secrete" - login_host: "localhost" - name: "{{ nova_galera_database }}" - state: "present" - delegate_to: "{{ groups['galera_all'][0] }}" - when: inventory_hostname == groups['nova_all'][0] - tags: - - mysql-db-setup - - name: Grant access to the DB for the service - mysql_user: - login_user: "root" - login_password: "secrete" - login_host: "localhost" - name: "{{ nova_galera_database }}" - password: "{{ nova_container_mysql_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ nova_galera_database }}.*:ALL" - with_items: - - "localhost" - - "%" - delegate_to: "{{ groups['galera_all'][0] }}" - when: inventory_hostname == groups['nova_all'][0] - tags: - - mysql-db-setup - - name: Create API DB for service - mysql_db: - login_user: "{{ galera_root_user }}" - login_password: "{{ galera_root_password }}" - login_host: "{{ nova_api_galera_address }}" - name: "{{ nova_api_galera_database }}" - state: "present" - when: inventory_hostname == groups['nova_all'][0] - - name: Grant access to the API DB for the service - mysql_user: - login_user: "{{ galera_root_user }}" - login_password: "{{ galera_root_password }}" - login_host: "{{ nova_api_galera_address }}" - name: "{{ nova_api_galera_user }}" - password: "{{ nova_api_container_mysql_password }}" - host: "{{ item }}" - state: "present" - priv: "{{ nova_api_galera_database }}.*:ALL" - with_items: - - "localhost" - - "%" - when: inventory_hostname == groups['nova_all'][0] + when: + - inventory_hostname in groups['nova_all'] + - ansible_pkg_mgr == 'apt' + - include: ensure-rabbitmq.yml + vhost_name: "{{ nova_rabbitmq_vhost }}" + user_name: "{{ nova_rabbitmq_userid }}" + user_password: "{{ nova_rabbitmq_password }}" + host_name: groups['nova_all'][0] + - include: create-grant-db.yml + db_name: "{{ nova_galera_database }}" + db_password: "{{ nova_container_mysql_password }}" + host_name: groups['nova_all'][0] roles: - role: "{{ nova_rolename | default('os_nova') }}" vars_files: