From f529a266c590c4a5624be8c5df865d6e5b6e1640 Mon Sep 17 00:00:00 2001 From: Fatih Degirmenci Date: Fri, 1 May 2020 17:51:35 +0000 Subject: [PATCH] Create stack bootstrap-swconfig role Change-Id: I14aa6942c6c159b8def2b42045bcfc42738969f4 --- install.sh | 35 ++++++++ playbooks/bootstrap-swconfig.yaml | 26 ++++++ .../tasks/configure-offline-deployment.yaml | 62 +++++++++++++ .../tasks/configure-online-deployment.yaml | 72 +++++++++++++++ .../roles/bootstrap-swconfig/tasks/main.yaml | 89 +++++++++++++++++++ vars/kubernetes.yaml | 50 +++++++++++ 6 files changed, 334 insertions(+) create mode 100755 install.sh create mode 100644 playbooks/bootstrap-swconfig.yaml create mode 100644 playbooks/roles/bootstrap-swconfig/tasks/configure-offline-deployment.yaml create mode 100644 playbooks/roles/bootstrap-swconfig/tasks/configure-online-deployment.yaml create mode 100644 playbooks/roles/bootstrap-swconfig/tasks/main.yaml create mode 100644 vars/kubernetes.yaml diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..9d8a8b8 --- /dev/null +++ b/install.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# ============LICENSE_START======================================================= +# Copyright (C) 2019 The Nordix Foundation. 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +set -o errexit +set -o nounset +set -o pipefail + +#------------------------------------------------------------------------------- +# Bootstrap stack software configuration +#------------------------------------------------------------------------------- +echo "Info : Bootstrap stack software configuration" +echo "-------------------------------------------------------------------------" +cd "${ENGINE_PATH}" +ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \ + -i "${ENGINE_PATH}/engine/inventory/localhost.ini" \ + engine/stack/kubernetes/playbooks/bootstrap-swconfig.yaml +echo "-------------------------------------------------------------------------" + +# vim: set ts=2 sw=2 expandtab: diff --git a/playbooks/bootstrap-swconfig.yaml b/playbooks/bootstrap-swconfig.yaml new file mode 100644 index 0000000..5b42dba --- /dev/null +++ b/playbooks/bootstrap-swconfig.yaml @@ -0,0 +1,26 @@ +--- +# ============LICENSE_START======================================================= +# Copyright (C) 2019 The Nordix Foundation. 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +- hosts: localhost + connection: local + gather_facts: true + become: false + + roles: + - role: bootstrap-swconfig diff --git a/playbooks/roles/bootstrap-swconfig/tasks/configure-offline-deployment.yaml b/playbooks/roles/bootstrap-swconfig/tasks/configure-offline-deployment.yaml new file mode 100644 index 0000000..55bddd0 --- /dev/null +++ b/playbooks/roles/bootstrap-swconfig/tasks/configure-offline-deployment.yaml @@ -0,0 +1,62 @@ +--- +# ============LICENSE_START======================================================= +# Copyright (C) 2019 The Nordix Foundation. 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +- name: Delete outdated engine provisioner files and folders + file: + path: "{{ item }}" + state: absent + with_items: + - "{{ engine_workspace }}/offline/git/engine/engine/provisioner" + - "{{ engine_workspace }}/offline/git/engine/engine/inventory/group_vars/all/{{ provisioner_type }}.yaml" + +- name: Clone engine provisioner repository + git: + repo: "{{ engine_workspace }}/offline/git/engine-{{ provisioner_type }}" + dest: "{{ engine_workspace }}/offline/git/engine/engine/provisioner" + version: "{{ provisioners[provisioner_type].version }}" + force: true + +- name: Copy engine provisioner vars file into group_vars + copy: + src: "{{ engine_workspace }}/offline/git/engine-{{ provisioner_type }}/vars/{{ provisioner_type }}.yaml" + dest: "{{ engine_workspace }}/offline/git/engine/engine/inventory/group_vars/all/{{ provisioner_type }}.yaml" + force: true + +- name: Delete outdated engine installer vars files from group_vars + file: + path: "{{ item }}" + state: absent + with_items: + - "{{ engine_workspace }}/offline/git/engine/engine/installer" + - "{{ engine_workspace }}/offline/git/engine/engine/inventory/group_vars/all/{{ installer_type }}.yaml" + +- name: Clone engine installer repository + git: + repo: "{{ engine_workspace }}/offline/git/engine-{{ installer_type }}" + dest: "{{ engine_workspace }}/offline/git/engine/engine/installer" + version: "{{ installer[installer_type].version }}" + force: true + +- name: Copy engine installer vars file into group_vars + copy: + src: "{{ engine_workspace }}/offline/git/engine-{{ installer_type }}/vars/{{ installer_type }}.yaml" + dest: "{{ engine_workspace }}/offline/git/engine/engine/inventory/group_vars/all/{{ installer_type }}.yaml" + force: true + +# vim: set ts=2 sw=2 expandtab: diff --git a/playbooks/roles/bootstrap-swconfig/tasks/configure-online-deployment.yaml b/playbooks/roles/bootstrap-swconfig/tasks/configure-online-deployment.yaml new file mode 100644 index 0000000..f45182d --- /dev/null +++ b/playbooks/roles/bootstrap-swconfig/tasks/configure-online-deployment.yaml @@ -0,0 +1,72 @@ +--- +# ============LICENSE_START======================================================= +# Copyright (C) 2019 The Nordix Foundation. 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +- name: Delete outdated engine provisioner files and folders + file: + path: "{{ item }}" + state: absent + with_items: + - "{{ engine_path }}/engine/provisioner" + - "{{ engine_path }}/engine/inventory/group_vars/all/{{ provisioner_type }}.yaml" + +- name: Clone engine provisioner repository + git: + repo: "{{ provisioners[provisioner_type].src }}" + dest: "{{ engine_path }}/engine/provisioner" + version: "{{ provisioners[provisioner_type].version }}" + refspec: "{{ provisioners[provisioner_type].refspec | default(omit) }}" + force: true + environment: + http_proxy: "{{ lookup('env','http_proxy') }}" + https_proxy: "{{ lookup('env','https_proxy') }}" + no_proxy: "{{ lookup('env','no_proxy') }}" + +- name: Copy engine provisioner vars file into group_vars + copy: + src: "{{ engine_path }}/engine/provisioner/vars/{{ provisioner_type }}.yaml" + dest: "{{ engine_path }}/engine/inventory/group_vars/all/{{ provisioner_type }}.yaml" + force: true + +- name: Delete outdated engine installer files and folders + file: + path: "{{ item }}" + state: absent + with_items: + - "{{ engine_path }}/engine/installer" + - "{{ engine_path }}/engine/inventory/group_vars/all/{{ installer_type }}.yaml" + +- name: Clone engine installer repository + git: + repo: "{{ installers[installer_type].src }}" + dest: "{{ engine_path }}/engine/installer" + version: "{{ installers[installer_type].version }}" + refspec: "{{ installers[installer_type].refspec | default(omit) }}" + force: true + environment: + http_proxy: "{{ lookup('env','http_proxy') }}" + https_proxy: "{{ lookup('env','https_proxy') }}" + no_proxy: "{{ lookup('env','no_proxy') }}" + +- name: Copy engine installer vars file into group_vars + copy: + src: "{{ engine_path }}/engine/installer/vars/{{ installer_type }}.yaml" + dest: "{{ engine_path }}/engine/inventory/group_vars/all/{{ installer_type }}.yaml" + force: true + +# vim: set ts=2 sw=2 expandtab: diff --git a/playbooks/roles/bootstrap-swconfig/tasks/main.yaml b/playbooks/roles/bootstrap-swconfig/tasks/main.yaml new file mode 100644 index 0000000..60c6edd --- /dev/null +++ b/playbooks/roles/bootstrap-swconfig/tasks/main.yaml @@ -0,0 +1,89 @@ +--- +# ============LICENSE_START======================================================= +# Copyright (C) 2019 The Nordix Foundation. 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +- name: Set distribution + set_fact: + distro: "{{ ansible_distribution | lower }}{{ ansible_distribution_version | replace('.','') }}" + +- name: Log distribution to console + debug: + msg: 'Set distribution to {{ distro }}' + +- name: Fail if distribution is not valid for stack '{{ stack_type }}' + fail: + msg: "'{{ distro }}' is not a valid distribution for stack '{{ stack_type }}'" + when: distro not in distros + +- name: Set provisioner type + set_fact: + provisioner_type: "{{ details.type is defined | ternary('bifrost', 'heat') }}" + +- name: Log provisioner type to console + debug: + msg: 'Set provisioner type to {{ provisioner_type }}' + +- name: Fail if the selected provisioner is not valid for stack '{{ stack_type }}' + fail: + msg: "'{{ provisioner_type }}' is not a valid provisioner for stack '{{ stack_type }}'" + when: provisioner_type not in provisioners + +- name: Set installer type + set_fact: + installer_type: 'kubespray' + when: deploy_scenario is search('k8-') + +- name: Log installer type to console + debug: + msg: 'Set installer type to {{ installer_type }}' + +- name: Fail if the selected installer is not valid for stack '{{ stack_type }}' + fail: + msg: "'{{ installer_type }}' is not a valid installer for stack '{{ stack_type }}'" + when: installer_type not in installers + +- name: Log deploy scenario to console + debug: + msg: 'Set deploy scenario to {{ deploy_scenario }}' + +- name: Fail if the deploy scenario is not valid for stack '{{ stack_type }}' + fail: + msg: "'{{ deploy_scenario }}' is not valid for stack '{{ stack_type }}'" + when: deploy_scenario not in scenarios + +# NOTE (fdegir): as we determine things dynamically, we need to record variables in order +# for them to become available subsequent tasks, roles, playbooks +- name: Record deployment variables to deployment variables file + blockinfile: + path: "{{ deployment_vars_file }}" + state: present + create: true + block: | + distro: "{{ distro }}" + provisioner_type: "{{ provisioner_type }}" + installer_type: "{{ installer_type }}" + marker: "# {mark} ANSIBLE MANAGED BLOCK engine-kubernetes" + +- name: Reload deployment variables + include_vars: "{{ deployment_vars_file }}" + +# NOTE (fdegir): Prepare provisioner and installer +- name: Prepare provisioner and installer for '{{ execution_mode }}' + include_tasks: "configure-{{ execution_mode }}.yaml" + +# vim: set ts=2 sw=2 expandtab: diff --git a/vars/kubernetes.yaml b/vars/kubernetes.yaml new file mode 100644 index 0000000..4404570 --- /dev/null +++ b/vars/kubernetes.yaml @@ -0,0 +1,50 @@ +--- +# ============LICENSE_START======================================================= +# Copyright (C) 2019 The Nordix Foundation. 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +distros: + - ubuntu1804 + +# NOTE (fdegir): versions point to poc branch +provisioners: + bifrost: + scm: git + src: ssh://localhost:47821/home/fdegir/repos/poc-nordix/bifrost + version: "{{ lookup('env', 'NORDIX_BIFROST_VERSION') | default('poc', true) }}" + heat: + scm: git + src: ssh://localhost:47821/home/fdegir/repos/poc-nordix/heat + version: "{{ lookup('env', 'NORDIX_HEAT_VERSION') | default('poc', true) }}" + +installers: + kubespray: + scm: git + src: ssh://localhost:47821/home/fdegir/repos/poc-nordix/kubespray + version: "{{ lookup('env', 'NORDIX_KUBESPRAY_VERSION') | default('poc', true) }}" + +apps: + - ceph + - prometheus + +scenarios: + k8-multus-plugins: + curated_apps: + - ceph + - prometheus + +# vim: set ts=2 sw=2 expandtab: -- 2.25.1