diff --git a/doc/source/roles/role-tripleo-cellv2.rst b/doc/source/roles/role-tripleo-cellv2.rst new file mode 100644 index 000000000..173a37edc --- /dev/null +++ b/doc/source/roles/role-tripleo-cellv2.rst @@ -0,0 +1,6 @@ +===================== +Role - tripleo-cellv2 +===================== + +.. ansibleautoplugin:: + :role: tripleo_ansible/roles/tripleo-cellv2 diff --git a/tripleo_ansible/playbooks/create-nova-cell-v2.yaml b/tripleo_ansible/playbooks/create-nova-cell-v2.yaml new file mode 100644 index 000000000..1f4395ba1 --- /dev/null +++ b/tripleo_ansible/playbooks/create-nova-cell-v2.yaml @@ -0,0 +1,80 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + +- hosts: Controller[0] + remote_user: stack + gather_facts: true + vars: + tripleo_cellv2_cell_name: "{{ tripleo_cellv2_cell_name }}" + # containercli can be tropped when we fully switched to podman + tripleo_cellv2_containercli: "{{ tripleo_cellv2_containercli }}" + tripleo_cellv2_cellcontroller_group: "{{ groups['CellController'] }}" + tasks: + - import_role: + name: tripleo-cellv2 + tasks_from: check_cell_exist.yml + +- hosts: CellController[0] + remote_user: stack + gather_facts: true + vars: + tripleo_cellv2_cell_name: "{{ tripleo_cellv2_cell_name }}" + # containercli can be tropped when we fully switched to podman + tripleo_cellv2_containercli: "{{ tripleo_cellv2_containercli }}" + tripleo_cellv2_cellcontroller_group: "{{ groups['CellController'] }}" + tasks: + - import_role: + name: tripleo-cellv2 + tasks_from: extract_cell_information.yml + +- hosts: Controller[0] + remote_user: stack + gather_facts: true + vars: + tripleo_cellv2_cell_name: "{{ tripleo_cellv2_cell_name }}" + # containercli can be tropped when we fully switched to podman + tripleo_cellv2_containercli: "{{ tripleo_cellv2_containercli }}" + tripleo_cellv2_cellcontroller_group: "{{ groups['CellController'] }}" + tasks: + - import_role: + name: tripleo-cellv2 + tasks_from: create_cell.yml + +- hosts: Controller + remote_user: stack + gather_facts: true + vars: + tripleo_cellv2_cell_name: "{{ tripleo_cellv2_cell_name }}" + # containercli can be tropped when we fully switched to podman + tripleo_cellv2_containercli: "{{ tripleo_cellv2_containercli }}" + tripleo_cellv2_cellcontroller_group: "{{ groups['CellController'] }}" + tasks: + - import_role: + name: tripleo-cellv2 + tasks_from: add_internalapi_hosts_entries.yml + +- hosts: Controller[0] + remote_user: stack + gather_facts: true + vars: + tripleo_cellv2_cell_name: "{{ tripleo_cellv2_cell_name }}" + # containercli can be tropped when we fully switched to podman + tripleo_cellv2_containercli: "{{ tripleo_cellv2_containercli }}" + tripleo_cellv2_cellcontroller_group: "{{ groups['CellController'] }}" + tasks: + - import_role: + name: tripleo-cellv2 + tasks_from: discover_hosts.yml diff --git a/tripleo_ansible/roles/tripleo-cellv2/defaults/main.yml b/tripleo_ansible/roles/tripleo-cellv2/defaults/main.yml new file mode 100644 index 000000000..766c5f2c2 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/defaults/main.yml @@ -0,0 +1,27 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +# All variables intended for modification should place placed in this file. + +tripleo_cellv2_debug: false +tripleo_cellv2_cell_name: "" +# containercli can be tropped when we fully switched to podman +tripleo_cellv2_containercli: "docker" + +tripleo_cellv2_cellcontroller_group: "{{ groups['CellController'] }}" +tripleo_cellv2_cell_database_vip: "{{ hostvars[tripleo_cellv2_cellcontroller_group[0]]['cell_database_vip'] }}" +tripleo_cellv2_cell_transport_url: "{{ hostvars[tripleo_cellv2_cellcontroller_group[0]]['cell_transport_url'] }}" diff --git a/tripleo_ansible/roles/tripleo-cellv2/handlers/main.yml b/tripleo_ansible/roles/tripleo-cellv2/handlers/main.yml new file mode 100644 index 000000000..0950a97f1 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/handlers/main.yml @@ -0,0 +1,29 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: nova restart podman + systemd: + name: "{{ item }}" + state: restarted + with_items: + - tripleo_nova_api + - tripleo_nova_conductor + - tripleo_nova_scheduler + when: containercli == "podman" + +- name: nova restart docker + command: docker restart nova_api nova_scheduler nova_conductor + when: containercli == "docker" diff --git a/tripleo_ansible/roles/tripleo-cellv2/meta/main.yml b/tripleo_ansible/roles/tripleo-cellv2/meta/main.yml new file mode 100644 index 000000000..f4af2ea9f --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/meta/main.yml @@ -0,0 +1,44 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +galaxy_info: + author: OpenStack + description: TripleO OpenStack Role -- tripleo-cellv2 + company: Red Hat + license: Apache-2.0 + min_ansible_version: 2.7 + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: + - name: Fedora + versions: + - 28 + - name: CentOS + versions: + - 7 + + galaxy_tags: + - tripleo + + +# List your role dependencies here, one per line. Be sure to remove the '[]' above, +# if you add dependencies to this list. +dependencies: [] diff --git a/tripleo_ansible/roles/tripleo-cellv2/molecule/default/Dockerfile b/tripleo_ansible/roles/tripleo-cellv2/molecule/default/Dockerfile new file mode 100644 index 000000000..1b91a0e0b --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/molecule/default/Dockerfile @@ -0,0 +1,37 @@ +# Molecule managed +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi + +{% for pkg in item.easy_install | default([]) %} +# install pip for centos where there is no python-pip rpm in default repos +RUN easy_install {{ pkg }} +{% endfor %} + + +CMD ["sh", "-c", "while true; do sleep 10000; done"] diff --git a/tripleo_ansible/roles/tripleo-cellv2/molecule/default/molecule.yml b/tripleo_ansible/roles/tripleo-cellv2/molecule/default/molecule.yml new file mode 100644 index 000000000..3a32890d4 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/molecule/default/molecule.yml @@ -0,0 +1,48 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos7 + hostname: centos7 + image: centos:7 + dockerfile: Dockerfile + pkg_extras: python-setuptools + easy_install: + - pip + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + + - name: fedora28 + hostname: fedora28 + image: fedora:28 + dockerfile: Dockerfile + pkg_extras: python*-setuptools + environment: + <<: *env + +provisioner: + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - verify + - destroy + +lint: + enabled: false + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/tripleo_ansible/roles/tripleo-cellv2/molecule/default/playbook.yml b/tripleo_ansible/roles/tripleo-cellv2/molecule/default/playbook.yml new file mode 100644 index 000000000..81805ea54 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/molecule/default/playbook.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Converge + hosts: all + roles: + - role: "tripleo-cellv2" diff --git a/tripleo_ansible/roles/tripleo-cellv2/molecule/default/prepare.yml b/tripleo_ansible/roles/tripleo-cellv2/molecule/default/prepare.yml new file mode 100644 index 000000000..ef85c3128 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/molecule/default/prepare.yml @@ -0,0 +1,21 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Prepare + hosts: all + roles: + - role: test_deps diff --git a/tripleo_ansible/roles/tripleo-cellv2/tasks/add_internalapi_hosts_entries.yml b/tripleo_ansible/roles/tripleo-cellv2/tasks/add_internalapi_hosts_entries.yml new file mode 100644 index 000000000..99b50425a --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/tasks/add_internalapi_hosts_entries.yml @@ -0,0 +1,38 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Add CellController internalapi to control plan controller + become: true + lineinfile: + dest: "/etc/hosts" + regexp: ".*{{ hostvars[item]['internal_api_hostname'] }}.*$" + line: >- + {{ hostvars[item]['internal_api_ip'] }} + {{ hostvars[item]['internal_api_hostname'] }} + {{ hostvars[item]['internal_api_hostname'].split('.')[:2] | join('.') }} + insertafter: "# HEAT_HOSTS_END" + state: present + when: + - hostvars[item]['internal_api_ip'] is defined + - hostvars[item]['internal_api_hostname'] is defined + with_items: "{{ tripleo_cellv2_cellcontroller_group }}" + register: hosts_result + notify: + - nova restart podman + - nova restart docker + tags: + - hosts + - create diff --git a/tripleo_ansible/roles/tripleo-cellv2/tasks/check_cell_exist.yml b/tripleo_ansible/roles/tripleo-cellv2/tasks/check_cell_exist.yml new file mode 100644 index 000000000..3937ac245 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/tasks/check_cell_exist.yml @@ -0,0 +1,37 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Check if cell exist + block: + - name: Fail if cell_name or containercli are not passed + fail: msg="Both tripleo_cellv2_cell_name and tripleo_cellv2_containercli are mandatory parameters!" + when: tripleo_cellv2_cell_name is not defined or tripleo_cellv2_containercli is not defined + - name: Check if cell is already created + become: true + shell: |- + set -o pipefail + {{ tripleo_cellv2_containercli }} exec -i -u root nova_api \ + nova-manage {{ (tripleo_cellv2_debug | bool) | ternary('--debug', '') }} \ + cell_v2 list_cells | grep {{ tripleo_cellv2_cell_name }} + ignore_errors: true + register: cell_check_result + - name: Fail if cell already exist + fail: msg="Cell with name {{ tripleo_cellv2_cell_name }} already exist!" + when: cell_check_result.rc == 0 + tags: + - check + - extract + - create diff --git a/tripleo_ansible/roles/tripleo-cellv2/tasks/create_cell.yml b/tripleo_ansible/roles/tripleo-cellv2/tasks/create_cell.yml new file mode 100644 index 000000000..6750f1810 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/tasks/create_cell.yml @@ -0,0 +1,35 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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 new Cell + become: true + block: + - name: Create Cell + shell: >- + {{ tripleo_cellv2_containercli }} exec -i -u root nova_api + nova-manage cell_v2 create_cell --name {{ tripleo_cellv2_cell_name }} + --database_connection "{scheme}://{username}:{password}@{{ tripleo_cellv2_cell_database_vip }}/nova?{query}" + --transport-url "{{ tripleo_cellv2_cell_transport_url }}" + + - name: List Cells + shell: > + {{ tripleo_cellv2_containercli }} exec -i -u root nova_api + nova-manage cell_v2 list_cells + register: cells + + - debug: var=cells.stdout_lines + tags: + - create diff --git a/tripleo_ansible/roles/tripleo-cellv2/tasks/discover_hosts.yml b/tripleo_ansible/roles/tripleo-cellv2/tasks/discover_hosts.yml new file mode 100644 index 000000000..7d9848a15 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/tasks/discover_hosts.yml @@ -0,0 +1,30 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Discover cell nodes + become: true + block: + - name: Discover hosts + shell: >- + {{ tripleo_cellv2_containercli }} exec -i -u root nova_api + nova-manage cell_v2 discover_hosts --by-service --verbose + + - name: List Cells + shell: >- + {{ tripleo_cellv2_containercli }} exec -i -u root nova_api + nova-manage cell_v2 list_cells + tags: + - discover diff --git a/tripleo_ansible/roles/tripleo-cellv2/tasks/extract_cell_information.yml b/tripleo_ansible/roles/tripleo-cellv2/tasks/extract_cell_information.yml new file mode 100644 index 000000000..089c59536 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-cellv2/tasks/extract_cell_information.yml @@ -0,0 +1,39 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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: Extract transport_url and database connection from one CellController + become: true + block: + - name: Extract transport_url from CellController + command: >- + crudini --get /var/lib/config-data/nova/etc/nova/nova.conf DEFAULT transport_url + register: cell_transport_url_result + + - name: Set fact cell_transport_url + set_fact: + cell_transport_url: "{{ cell_transport_url_result.stdout }}" + + - name: Extract database connection from CellController + command: >- + crudini --get /var/lib/config-data/nova/etc/nova/nova.conf database connection + register: cell_database_vip_result + + - name: Set fact cell_database_vip + set_fact: + cell_database_vip: "{{ cell_database_vip_result.stdout |regex_replace('.*@(.*?)/.*$', '\\1') }}" + tags: + - extract + - create diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index f625a5122..e6eda74af 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -30,6 +30,7 @@ - tripleo-ansible-centos-7-molecule-tripleo-container-image-prepare - tripleo-ansible-centos-7-molecule-tripleo-firewall - tripleo-ansible-centos-7-molecule-tripleo-securetty + - tripleo-ansible-centos-7-molecule-tripleo-cellv2 gate: jobs: - tripleo-ansible-centos-7-molecule-aide @@ -60,6 +61,7 @@ - tripleo-ansible-centos-7-molecule-tripleo-container-image-prepare - tripleo-ansible-centos-7-molecule-tripleo-firewall - tripleo-ansible-centos-7-molecule-tripleo-securetty + - tripleo-ansible-centos-7-molecule-tripleo-cellv2 name: tripleo-ansible-molecule-jobs - job: files: @@ -265,3 +267,10 @@ parent: tripleo-ansible-centos-7-base vars: tripleo_role_name: tripleo-securetty +- job: + files: + - ^tripleo_ansible/roles/tripleo-cellv2/.* + name: tripleo-ansible-centos-7-molecule-tripleo-cellv2 + parent: tripleo-ansible-centos-7-base + vars: + tripleo_role_name: tripleo-cellv2