diff options
Diffstat (limited to 'xci/infra/bifrost/playbooks')
-rw-r--r-- | xci/infra/bifrost/playbooks/opnfv-virtual.yml | 167 | ||||
-rw-r--r-- | xci/infra/bifrost/playbooks/roles/common/venv_python_path.yml | 34 | ||||
-rw-r--r-- | xci/infra/bifrost/playbooks/wait-for-baremetal.yml | 17 | ||||
-rw-r--r-- | xci/infra/bifrost/playbooks/xci-prepare-env.yml | 118 | ||||
-rw-r--r-- | xci/infra/bifrost/playbooks/xci-setup-nodes.yml | 76 |
5 files changed, 412 insertions, 0 deletions
diff --git a/xci/infra/bifrost/playbooks/opnfv-virtual.yml b/xci/infra/bifrost/playbooks/opnfv-virtual.yml new file mode 100644 index 00000000..f97eae4b --- /dev/null +++ b/xci/infra/bifrost/playbooks/opnfv-virtual.yml @@ -0,0 +1,167 @@ +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2016 RedHat and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +--- +- hosts: opnfv + name: "Host and Ironic bootstrapping" + become: yes + gather_facts: yes + vars_files: + - "../vars/{{ ansible_os_family | lower }}.yml" + pre_tasks: + - name: Remove pre-existing leases file + file: path=/var/lib/misc/dnsmasq.leases state=absent + - name: "Override the ipv4_gateway setting" + set_fact: + ipv4_gateway: "192.168.122.1" + - name: Prepare the XCI pre-built images + block: + - name: Create the PXE directory + file: + path: /httpboot + state: directory + - name: Download the {{ xci_distro }} image checksum file + get_url: + dest: /httpboot/deployment_image.qcow2.sha256.txt + force: no + url: http://artifacts.opnfv.org/releng/xci/images/{{ xci_distro }}.qcow2.sha256.txt + timeout: 3000 + - name: Extract checksum + shell: awk '{print $1}' /httpboot/deployment_image.qcow2.sha256.txt + register: _image_checksum + - fail: + msg: "Failed to get image checksum" + when: _image_checksum == '' + - set_fact: + image_checksum: "{{ _image_checksum.stdout }}" + - name: Download the {{ xci_distro }} image file + get_url: + url: http://artifacts.opnfv.org/releng/xci/images/{{ xci_distro }}.qcow2 + checksum: "sha256:{{ image_checksum }}" + timeout: 3000 + dest: /httpboot/deployment_image.qcow2 + force: no + - name: Set correct mode for {{ xci_distro }}.qcow2 file + file: + path: /httpboot/deployment_image.qcow2 + mode: '0755' + owner: 'root' + group: 'root' + when: create_image_via_dib | bool == false + - name: Ensure /etc/hosts has good defaults + lineinfile: + create: yes + dest: "/etc/hosts" + regexp: "{{ item.regexp }}.*({{ ansible_hostname }}|localhost).*" + line: "{{ item.contents }}" + with_items: + - { regexp: '^127\.0\.0\.1', contents: '127.0.0.1 {{ ansible_hostname }} {{ ansible_fqdn }} localhost' } + - { regexp: '^::1', contents: '::1 {{ ansible_hostname }} {{ ansible_fqdn }} localhost ipv6-localhost ipv6-loopback' } + - name: Install required packages + package: + name: "{{ bifrost_required_devel_packages }}" + state: present + + roles: + - role: bifrost-prep-for-install + when: skip_install is not defined + - role: bifrost-keystone-install + - role: bifrost-ironic-install + cleaning: false + testing: false + enabled_hardware_types: ipmi + network_interface: "{{ ansible_default_ipv4.interface }}" + # Create the IPA image for ironic to boot the nodes and write the final distro in the hard drive + # fedora is used because it is the only one working with ericsson-pod2 (it has support for newer hardware) + - role: bifrost-create-dib-image + dib_imagename: "{{ http_boot_folder }}/ipa" + build_ramdisk: false + dib_os_element: "{{ ipa_dib_os_element|default('fedora') }}" + dib_elements: "ironic-agent {{ ipa_extra_dib_elements | default('') }}" + dib_notmpfs: true + when: + - create_ipa_image | bool == true + # Create the final distro image + - role: bifrost-create-dib-image + dib_imagetype: "qcow2" + dib_imagename: "{{deploy_image}}" + dib_env_vars: + DIB_PYTHON_VERSION: 2 + dib_os_element: "{{ lookup('env','DIB_OS_ELEMENT') }}" + dib_os_release: "{{ lookup('env', 'DIB_OS_RELEASE') }}" + extra_dib_elements: "{{ lookup('env', 'EXTRA_DIB_ELEMENTS') | default('') }}" + dib_elements: "vm enable-serial-console simple-init devuser openssh-server growroot pip-and-virtualenv {{ extra_dib_elements }}" + dib_packages: "{{ lookup('env', 'DIB_OS_PACKAGES') }}" + dib_notmpfs: true + when: + - create_image_via_dib | bool == true + - transform_boot_image | bool == false + - role: bifrost-keystone-client-config + clouds: + bifrost: + config_username: "{{ ironic.keystone.default_username }}" + config_password: "{{ ironic.keystone.default_password }}" + config_project_name: "baremetal" + config_region_name: "{{ keystone.bootstrap.region_name }}" + config_auth_url: "{{ keystone.bootstrap.public_url }}" + environment: + http_proxy: "{{ lookup('env','http_proxy') }}" + https_proxy: "{{ lookup('env','https_proxy') }}" + no_proxy: "{{ lookup('env','no_proxy') }}" + +- hosts: baremetal + name: "Enrollment and Deployment" + vars: + multinode_testing: "{{ inventory_dhcp | bool == true }}" + become: no + gather_facts: False + tasks: + - name: Gathering facts + setup: + delegate_to: opnfv + delegate_facts: False + - name: Find network interface in the OPNFV node + set_fact: + network_interface: "{{ ansible_default_ipv4.interface }}" + - import_role: + name: ironic-enroll-dynamic + private: True + delegate_to: opnfv + - import_role: + name: ironic-inspect-node + private: True + delegate_to: opnfv + when: inspect_nodes | default('false') | bool == true + - import_role: + name: bifrost-configdrives-dynamic + private: True + vars: + ipv4_nameserver: "{{ host_info[inventory_hostname]['public']['dns'] | list }}" + delegate_to: opnfv + - import_role: + name: bifrost-deploy-nodes-dynamic + private: True + delegate_to: opnfv + environment: + http_proxy: "{{ lookup('env','http_proxy') }}" + https_proxy: "{{ lookup('env','https_proxy') }}" + no_proxy: "{{ lookup('env','no_proxy') }}" + +- hosts: baremetal + name: "Deploy machines." + become: no + serial: 1 + gather_facts: False + tasks: + #- name: Gathering facts + #setup: + #delegate_to: opnfv + #delegate_facts: False + - import_role: + name: bifrost-prepare-for-test-dynamic + delegate_to: opnfv diff --git a/xci/infra/bifrost/playbooks/roles/common/venv_python_path.yml b/xci/infra/bifrost/playbooks/roles/common/venv_python_path.yml new file mode 100644 index 00000000..7f7ad670 --- /dev/null +++ b/xci/infra/bifrost/playbooks/roles/common/venv_python_path.yml @@ -0,0 +1,34 @@ +# 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: "If VENV is set in the environment, enable installation into venv" + set_fact: + enable_venv: true + when: lookup('env', 'VENV') | length > 0 + +- name: "Retrieve venv python path" + shell: "/bin/echo -e \"import sys\\nprint(':'.join(sys.path))\" | {{ ansible_python.get('executable', '/usr/bin/python').split('/')[-1] }}" + environment: "{{ bifrost_venv_env | default({}) }}" + register: venv_pythonpath_result + when: enable_venv + +- name: "Compute venv python path" + set_fact: + venv_pythonpath: + PYTHONPATH: "{{ venv_pythonpath_result.get('stdout', '') }}" + when: enable_venv + +- name: "Compute proper complete venv including proper Python path" + set_fact: + venv: "{{ venv | default({}) | combine(bifrost_venv_env | default({})) | combine(venv_pythonpath | default({})) }}" + diff --git a/xci/infra/bifrost/playbooks/wait-for-baremetal.yml b/xci/infra/bifrost/playbooks/wait-for-baremetal.yml new file mode 100644 index 00000000..96aab29c --- /dev/null +++ b/xci/infra/bifrost/playbooks/wait-for-baremetal.yml @@ -0,0 +1,17 @@ +# ironic needs to boot the server again to install the OS in the hard drive +# we are currently modifying opnfv vm networking config while ironic is +# doing that and it sometimes fail because of networking glitches. We should +# wait until the OS is installed to do the opnfv config + +- hosts: baremetal + name: "Wait for baremetal blades to be ready" + become: no + gather_facts: False + tasks: + - name: "Wait for nodes to reboot." + wait_for: state=stopped port=22 host={{ ipv4_address }} timeout=5000 + delegate_to: opnfv + - name: "Wait for nodes to become available." + wait_for: state=started port=22 host={{ ipv4_address }} timeout=5000 + delegate_to: opnfv + diff --git a/xci/infra/bifrost/playbooks/xci-prepare-env.yml b/xci/infra/bifrost/playbooks/xci-prepare-env.yml new file mode 100644 index 00000000..d576324d --- /dev/null +++ b/xci/infra/bifrost/playbooks/xci-prepare-env.yml @@ -0,0 +1,118 @@ +- name: Prepare deployment host + hosts: deployment_host + gather_facts: True + tasks: + - name: Ensure common private key has correct permissions + file: + path: "{{ xci_path }}/xci/scripts/vm/id_rsa_for_dib" + mode: "0600" + + - name: Remove host from known_hosts file if necessary + shell: + ssh-keygen -R {{ hostvars['opnfv'].ip }} + failed_when: false + +- name: Prepare the OPNFV host + hosts: opnfv + gather_facts: True + vars_files: + - "{{ xci_path }}/xci/var/opnfv.yml" + tasks: + + - name: Configure SSH key for devuser + user: + name: devuser + generate_ssh_key: yes + ssh_key_bits: 2048 + ssh_key_comment: xci + ssh_key_type: rsa + state: present + + - name: Determine local user + become: no + local_action: command whoami + changed_when: False + register: _ansible_user + + - name: Fetch local SSH key + delegate_to: localhost + become: no + slurp: + src: "/home/{{ _ansible_user.stdout }}/.ssh/id_rsa.pub" + register: _local_ssh_key + + - name: "Configure {{ inventory_hostname }} authorized_keys file (devuser)" + authorized_key: + exclusive: no + user: devuser + state: present + manage_dir: yes + key: "{{ _local_ssh_key['content'] | b64decode }}" + comment: "deployer's key" + + - name: "Configure {{ inventory_hostname }} authorized_keys file (root)" + authorized_key: + exclusive: no + user: root + state: present + manage_dir: yes + key: "{{ _local_ssh_key['content'] | b64decode }}" + comment: "deployer's key" + become: yes + + - name: Ensure /httpboot directory exists + file: + path: /httpboot + state: directory + become: yes + + # Directory must exist before passing the static config + - name: "Setup Inventory DHCP Hosts Directory" + file: + path: "/etc/dnsmasq.d/bifrost.dhcp-hosts.d" + state: directory + owner: "root" + group: "root" + mode: 0755 + become: yes + + - name: Copy bifrost files + copy: + src: "{{ item.src }}" + dest: "{{ item.dst }}" + with_items: + - { src: '/tmp/baremetal.json', dst: '/tmp/baremetal.json' } + - { src: '/tmp/baremetalstaticips', dst: '/etc/dnsmasq.d/bifrost.dhcp-hosts.d/baremetalstaticips' } + become: yes + + - name: Copy original qcow2 image to OPNFV VM + synchronize: + src: "{{ xci_cache }}/{{ item }}" + dest: /httpboot/ + recursive: yes + delete: yes + with_items: + - "deployment_image.qcow2" + - "deployment_image.qcow2.sha256.txt" + become: yes + + - name: Configure DNS on openSUSE + block: + - stat: + path: /etc/resolv.conf.netconfig + register: _resolv_conf_netconfig + - shell: | + mv /etc/resolv.conf.netconfig /etc/resolv.conf + become: yes + when: _resolv_conf_netconfig.stat.exists + when: ansible_pkg_mgr == 'zypper' + + #TODO: Find a way to do this with Ansible + - name: Make sure the default gateway is correct + shell: "ip route del default" + become: yes + + #TODO: Find a way to do this with Ansible + - name: Make sure the default gateway is correct + shell: "ip route add default via {{ host_info[inventory_hostname].public.gateway }}" + become: yes diff --git a/xci/infra/bifrost/playbooks/xci-setup-nodes.yml b/xci/infra/bifrost/playbooks/xci-setup-nodes.yml new file mode 100644 index 00000000..a0f92159 --- /dev/null +++ b/xci/infra/bifrost/playbooks/xci-setup-nodes.yml @@ -0,0 +1,76 @@ +--- +# SPDX-license-identifier: Apache-2.0 +############################################################################## +# Copyright (c) 2018 SUSE LINUX GmbH. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +- hosts: deployment_host + name: "Bootstrap XCI hardware resources and prepare provisioning environment" + gather_facts: yes + vars_files: + - "{{ pdf_file }}" + - "{{ idf_file }}" + - "{{ xci_path }}/xci/var/opnfv_vm_pdf.yml" + - "{{ xci_path }}/xci/var/opnfv_vm_idf.yml" + - "{{ xci_path }}/xci/var/opnfv.yml" + pre_tasks: + - name: Load distribution variables + include_vars: + file: "{{ xci_path }}/xci/var/{{ ansible_os_family }}.yml" + roles: + - role: create-nodes + become: yes + - role: clone-repository + project: "opnfv/bifrost" + repo: "{{ openstack_bifrost_git_url }}" + dest: "{{ xci_cache }}/repos/bifrost" + version: "{{ openstack_bifrost_version }}" + tasks: + - name: Wait for host to come back to life + local_action: + module: wait_for + host: "{{ opnfv_vm_ip }}" + delay: 15 + state: started + port: 22 + connect_timeout: 10 + timeout: 10180 + + # No ansible module for brctl found + - name: Add pxe interface to the bridge + shell: "brctl addif {{ item.bridge }} {{ item.interface }}" + become: true + when: baremetal | bool == true + with_items: + - { bridge: "{{ network_bridge_admin }}", interface: "{{ network_interface_admin }}" } + - { bridge: "{{ network_bridge_mgmt }}", interface: "{{ network_interface_mgmt }}" } + + - name: Load distribution variables + include_vars: + file: "{{ xci_path }}/xci/var/{{ ansible_os_family }}.yml" + - name: Synchronize local development bifrost repository to XCI paths + # command module is much faster than the copy module + synchronize: + src: "{{ openstack_bifrost_dev_path }}" + dest: "{{ xci_cache }}/repos/bifrost" + recursive: yes + delete: yes + when: + - openstack_bifrost_dev_path != "" + - name: combine opnfv/releng-xci and openstack/bifrost scripts/playbooks + copy: + src: "{{ xci_path}}/xci/infra/bifrost/" + dest: "{{ xci_cache }}/repos/bifrost" + - name: "Ensure /etc/hosts has good defaults" + lineinfile: + dest: "/etc/hosts" + regexp: "{{ item.regexp }}.*({{ ansible_hostname }}|localhost).*" + line: "{{ item.contents }}" + become: yes + with_items: + - { regexp: '^127\.0\.0\.1', contents: '127.0.0.1 {{ ansible_hostname }} {{ ansible_fqdn }} localhost' } + - { regexp: '^::1', contents: '::1 {{ ansible_hostname }} {{ ansible_fqdn }} localhost ipv6-localhost ipv6-loopback' } |