From 0273bf5fd02cdff2712f6f7bb5e75aa7b068f25e Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Thu, 19 May 2016 15:41:31 +0100 Subject: [PATCH] Initial testing commit --- playbooks/test-install-galera.yml | 23 +++++++ playbooks/test-install-infra.yml | 20 +++++++ playbooks/test-install-keystone.yml | 53 +++++++++++++++++ playbooks/test-install-memcached.yml | 23 +++++++ playbooks/test-install-rabbitmq.yml | 23 +++++++ playbooks/test-install-swift.yml | 32 ++++++++++ playbooks/test-prepare-containers.yml | 32 ++++++++++ playbooks/test-prepare-host.yml | 60 +++++++++++++++++++ playbooks/test-prepare-keys.yml | 33 ++++++++++ playbooks/test-setup-swifthosts.yml | 86 +++++++++++++++++++++++++++ playbooks/test.yml | 31 ++++++++++ 11 files changed, 416 insertions(+) create mode 100644 playbooks/test-install-galera.yml create mode 100644 playbooks/test-install-infra.yml create mode 100644 playbooks/test-install-keystone.yml create mode 100644 playbooks/test-install-memcached.yml create mode 100644 playbooks/test-install-rabbitmq.yml create mode 100644 playbooks/test-install-swift.yml create mode 100644 playbooks/test-prepare-containers.yml create mode 100644 playbooks/test-prepare-host.yml create mode 100644 playbooks/test-prepare-keys.yml create mode 100644 playbooks/test-setup-swifthosts.yml create mode 100644 playbooks/test.yml diff --git a/playbooks/test-install-galera.yml b/playbooks/test-install-galera.yml new file mode 100644 index 00000000..49fc9ca6 --- /dev/null +++ b/playbooks/test-install-galera.yml @@ -0,0 +1,23 @@ +--- +# 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: Deploy galera + hosts: galera_all + user: root + gather_facts: true + roles: + - role: "galera_server" + vars_files: + - test-vars.yml diff --git a/playbooks/test-install-infra.yml b/playbooks/test-install-infra.yml new file mode 100644 index 00000000..67828f71 --- /dev/null +++ b/playbooks/test-install-infra.yml @@ -0,0 +1,20 @@ +--- +# 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. + +- include: test-install-memcached.yml + +- include: test-install-rabbitmq.yml + +- include: test-install-galera.yml diff --git a/playbooks/test-install-keystone.yml b/playbooks/test-install-keystone.yml new file mode 100644 index 00000000..114494f5 --- /dev/null +++ b/playbooks/test-install-keystone.yml @@ -0,0 +1,53 @@ +--- +# 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: Playbook for deploying keystone + hosts: keystone_all + user: root + gather_facts: true + pre_tasks: + - name: Create DB for service + mysql_db: + login_user: "root" + login_password: "secrete" + login_host: "localhost" + name: "{{ 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 + roles: + - role: os_keystone + vars_files: + - test-vars.yml + diff --git a/playbooks/test-install-memcached.yml b/playbooks/test-install-memcached.yml new file mode 100644 index 00000000..db4ecfb7 --- /dev/null +++ b/playbooks/test-install-memcached.yml @@ -0,0 +1,23 @@ +--- +# 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: Deploy galera + hosts: memcached_all + user: root + gather_facts: true + roles: + - role: "memcached_server" + vars_files: + - test-vars.yml diff --git a/playbooks/test-install-rabbitmq.yml b/playbooks/test-install-rabbitmq.yml new file mode 100644 index 00000000..f5aa25ec --- /dev/null +++ b/playbooks/test-install-rabbitmq.yml @@ -0,0 +1,23 @@ +--- +# 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: Deploy Rabbitmq + hosts: rabbitmq_all + user: root + gather_facts: true + roles: + - role: "rabbitmq_server" + vars_files: + - test-vars.yml diff --git a/playbooks/test-install-swift.yml b/playbooks/test-install-swift.yml new file mode 100644 index 00000000..aee9ae3d --- /dev/null +++ b/playbooks/test-install-swift.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. + +- include: test-setup-swifthosts.yml + +- name: Playbook for deploying swift + hosts: swift_all + user: root + gather_facts: true + pre_tasks: + - name: Set swift replication address (container) + set_fact: + replication_address: "{{ hostvars[inventory_hostname]['container_networks']['replication_address']['address'] }}" + when: + - inventory_hostname in groups['swift_all'] + - hostvars[inventory_hostname]['container_networks']['replication_address']['address'] is defined + roles: + - role: "{{ rolename | basename }}" + vars_files: + - test-vars.yml diff --git a/playbooks/test-prepare-containers.yml b/playbooks/test-prepare-containers.yml new file mode 100644 index 00000000..c0d539ea --- /dev/null +++ b/playbooks/test-prepare-containers.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: Playbook for creating containers + hosts: all_containers + gather_facts: false + roles: + - role: "lxc_container_create" + lxc_container_release: trusty + lxc_container_backing_store: dir + global_environment_variables: + PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + post_tasks: + - name: Wait for ssh to be available + local_action: + module: wait_for + port: "{{ ansible_ssh_port | default('22') }}" + host: "{{ ansible_ssh_host | default(inventory_hostname) }}" + search_regex: OpenSSH + delay: 1 diff --git a/playbooks/test-prepare-host.yml b/playbooks/test-prepare-host.yml new file mode 100644 index 00000000..df473cd8 --- /dev/null +++ b/playbooks/test-prepare-host.yml @@ -0,0 +1,60 @@ +--- +# 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: Playbook for configuring the LXC host + hosts: localhost + pre_tasks: + - name: Update apt cache + apt: + update_cache: yes + when: ansible_os_family == 'Debian' + - name: Ensure roots new public ssh key is in authorized_keys + authorized_key: + user: root + key: "{{ hostvars['localhost']['lxc_container_ssh_key'] }}" + manage_dir: no + - set_fact: + lxc_container_ssh_key: "{{ hostvars['localhost']['lxc_container_ssh_key'] }}" + - name: Check if this is an OpenStack-CI nodepool instance + stat: + path: /etc/nodepool/provider + register: nodepool + - name: Set the files to copy into the container cache for OpenStack-CI instances + set_fact: + lxc_container_cache_files: + - { src: '/etc/pip.conf', dest: '/etc/pip.conf' } + - { src: '/etc/apt/apt.conf.d/99unauthenticated', dest: '/etc/apt/apt.conf.d/99unauthenticated' } + when: nodepool.stat.exists | bool + - name: Determine the existing Ubuntu repo configuration + shell: 'awk "/^deb .*ubuntu\/? {{ ansible_distribution_release }} main/ {print \$2; exit}" /etc/apt/sources.list' + register: ubuntu_repo + changed_when: false + - name: Set apt repo facts based on discovered information + set_fact: + lxc_container_template_main_apt_repo: "{{ ubuntu_repo.stdout }}" + lxc_container_template_security_apt_rep: "{{ ubuntu_repo.stdout }}" + post_tasks: + - name: Create bridges + shell: /sbin/brctl addbr {{ item.name }} || true + with_items: bridges + - name: IP bridges + command: /sbin/ifconfig {{ item.name }} {{ item.ip_addr }} netmask 255.255.255.0 + with_items: bridges + - name: Add iptables rule to ensure ssh checksum is correct + command: /sbin/iptables -A POSTROUTING -t mangle -p tcp --dport 22 -j CHECKSUM --checksum-fill + roles: + - role: "lxc_hosts" + vars_files: + - test-vars.yml diff --git a/playbooks/test-prepare-keys.yml b/playbooks/test-prepare-keys.yml new file mode 100644 index 00000000..a4fad4f5 --- /dev/null +++ b/playbooks/test-prepare-keys.yml @@ -0,0 +1,33 @@ +--- +# 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. + +# NOTE: we use become_user because setting become: no or become: false +# doesn't seem to override the ansible_become=true in the +# inventory +- name: Playbook for establishing ssh keys + hosts: localhost + become_user: "{{ ansible_ssh_user }}" + pre_tasks: + - name: Create ssh key pair for root + user: + name: "{{ ansible_ssh_user }}" + generate_ssh_key: "yes" + ssh_key_bits: 2048 + ssh_key_file: ".ssh/id_rsa" + - name: Get the calling user's key + command: cat ~/.ssh/id_rsa.pub + register: key_get + - set_fact: + lxc_container_ssh_key: "{{ key_get.stdout }}" diff --git a/playbooks/test-setup-swifthosts.yml b/playbooks/test-setup-swifthosts.yml new file mode 100644 index 00000000..b02dcb81 --- /dev/null +++ b/playbooks/test-setup-swifthosts.yml @@ -0,0 +1,86 @@ +--- +# 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: Swift setup + hosts: swift_hosts + user: root + gather_facts: true + pre_tasks: + - name: Ensure xfsprogs is installed on localhost + apt: + name: xfsprogs + state: present + delegate_to: "{{ physical_host }}" + run_once: true + - name: Ensure xfsprogs is installed on containers + apt: + name: xfsprogs + state: present + - name: Openstack directory Create + file: + state: directory + path: "/openstack/{{ item }}" + with_items: + - 'swift1' + - 'swift2' + - name: Create sparse Swift files + shell: "truncate -s 1024G /opt/{{container_name}}_{{ item }}.img" + args: + creates: "/opt/{{ container_name}}_{{ item }}.img" + with_items: + - 'swift1' + - 'swift2' + register: swift_create + delegate_to: "{{ physical_host }}" + - name: Format the Swift files + filesystem: + fstype: xfs + dev: "/opt/{{ container_name}}_{{ item }}.img" + when: swift_create | changed + with_items: + - 'swift1' + - 'swift2' + delegate_to: "{{ physical_host }}" + - name: Create the Swift fstab entries and mount the file systems + mount: + name: "/srv/{{ container_name }}_{{ item }}" + src: "/opt/{{ container_name }}_{{ item }}.img" + fstype: xfs + opts: 'loop,noatime,nodiratime,nobarrier,logbufs=8' + passno: 0 + dump: 0 + state: mounted + with_items: + - 'swift1' + - 'swift2' + register: mount_status + until: mount_status | success + retries: 5 + delay: 2 + delegate_to: "{{ physical_host }}" + - name: Swift extra lxc config + lxc_container: + name: "{{ container_name }}" + container_config: + - "lxc.mount.entry=/srv/{{ container_name }}_swift1 openstack/swift1 none bind 0 0" + - "lxc.mount.entry=/srv/{{ container_name }}_swift2 openstack/swift2 none bind 0 0" + delegate_to: "{{ physical_host }}" + - name: Wait for ssh to be available + local_action: + module: wait_for + port: "{{ ansible_ssh_port | default('22') }}" + host: "{{ ansible_ssh_host | default(inventory_hostname) }}" + search_regex: OpenSSH + delay: 1 diff --git a/playbooks/test.yml b/playbooks/test.yml new file mode 100644 index 00000000..1fcf3006 --- /dev/null +++ b/playbooks/test.yml @@ -0,0 +1,31 @@ +opyright 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. + +# Prepare the user ssh keys +- include: test-prepare-keys.yml + +# Prepare the host +- include: test-prepare-host.yml + +# Prepare the containers +- include: test-prepare-containers.yml + +# Install MariaDB/Memcached +- include: test-install-infra.yml + +# Install Keystone +- include: test-install-keystone.yml + +# Install Swift +- include: test-install-swift.yml