diff options
Diffstat (limited to 'xci/playbooks')
21 files changed, 442 insertions, 473 deletions
diff --git a/xci/playbooks/bootstrap-scenarios.yml b/xci/playbooks/bootstrap-scenarios.yml deleted file mode 100644 index d1331252..00000000 --- a/xci/playbooks/bootstrap-scenarios.yml +++ /dev/null @@ -1,43 +0,0 @@ ---- -# -# This file is aimed to be used by scenarios to plug into the XCI. -# Ideally, all they need to do at this point is to include their -# role using a statement like the following one -# -# - name: Include foobar role -# include_role: -# name: "foobar" -# when: deploy_scenario == "foobar" - -- name: Prepare everything to run the os-nosdn-nofeature scenario - include_role: - name: "os-nosdn-nofeature" - when: deploy_scenario == 'os-nosdn-nofeature' -- name: Prepare everything to run the os-odl-nofeature scenario - include_role: - name: "os-odl-nofeature" - when: deploy_scenario == 'os-odl-nofeature' -- name: Prepare everything to run the os-odl-sfc scenario - include_role: - name: "os-odl-sfc" - when: deploy_scenario == 'os-odl-sfc' -- name: Prepare everything to run the os-odl-bgpvpn scenario - include_role: - name: "os-odl-bgpvpn" - when: deploy_scenario == 'os-odl-bgpvpn' -- name: Prepare everything to run the k8-canal-nofeature scenario - include_role: - name: "k8-canal-nofeature" - when: deploy_scenario == 'k8-canal-nofeature' -- name: Prepare everything to run the k8-canal-nofeature scenario - include_role: - name: "k8-calico-nofeature" - when: deploy_scenario == 'k8-calico-nofeature' -- name: Prepare everything to run the k8-flannel-nofeature scenario - include_role: - name: "k8-flannel-nofeature" - when: deploy_scenario == 'k8-flannel-nofeature' -- name: Prepare everything to run the k8-nosdn-nofeature scenario - include_role: - name: "k8-nosdn-nofeature" - when: deploy_scenario == 'k8-nosdn-nofeature' diff --git a/xci/playbooks/configure-localhost.yml b/xci/playbooks/configure-localhost.yml index 5f091c92..5b64c785 100644 --- a/xci/playbooks/configure-localhost.yml +++ b/xci/playbooks/configure-localhost.yml @@ -25,7 +25,6 @@ state: absent recurse: no with_items: - - "{{ xci_cache }}/repos" - "{{ log_path }} " - "{{ opnfv_ssh_host_keys_path }}" diff --git a/xci/playbooks/dynamic_inventory.py b/xci/playbooks/dynamic_inventory.py new file mode 100755 index 00000000..552a1337 --- /dev/null +++ b/xci/playbooks/dynamic_inventory.py @@ -0,0 +1,161 @@ +#!/usr/bin/python +# coding utf-8 + +# 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 +############################################################################## +# +# Based on https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/cobbler.py + +import argparse +import os +import sys +import yaml +import json + + +class XCIInventory(object): + def __init__(self): + super(XCIInventory, self).__init__() + self.inventory = {} + self.inventory['all'] = {} + self.inventory['all']['hosts'] = [] + self.inventory['all']['vars'] = {} + self.inventory['_meta'] = {} + self.inventory['_meta']['hostvars'] = {} + self.installer = os.environ.get('INSTALLER_TYPE', 'osa') + self.flavor = os.environ.get('XCI_FLAVOR', 'mini') + + # Static information for opnfv host for now + self.add_host('opnfv') + self.add_hostvar('opnfv', 'ansible_ssh_host', '192.168.122.2') + self.add_to_group('deployment', 'opnfv') + self.add_to_group('opnfv', 'opnfv') + + self.opnfv_networks = {} + self.opnfv_networks['opnfv'] = {} + self.opnfv_networks['opnfv']['admin'] = {} + self.opnfv_networks['opnfv']['admin']['address'] = '172.29.236.10/22' + self.opnfv_networks['opnfv']['public'] = {} + self.opnfv_networks['opnfv']['public']['address'] = '192.168.122.2/24' + self.opnfv_networks['opnfv']['public']['gateway'] = '192.168.122.1' + self.opnfv_networks['opnfv']['private'] = {} + self.opnfv_networks['opnfv']['private']['address'] = '172.29.240.10/22' + self.opnfv_networks['opnfv']['storage'] = {} + self.opnfv_networks['opnfv']['storage']['address'] = '172.29.244.10/24' + + self.read_pdf_idf() + + self.parse_args() + + if self.args.host: + self.dump(self.get_host_info(self.args.host)) + else: + self.dump(self.inventory) + + def parse_args(self): + parser = argparse.ArgumentParser(description='Produce an Ansible inventory based on PDF/IDF XCI files') + parser.add_argument('--list', action='store_true', default=True, help='List XCI hosts (default: True)') + parser.add_argument('--host', action='store', help='Get all the variables about a specific host') + self.args = parser.parse_args() + + def read_pdf_idf(self): + pdf_file = os.path.dirname(os.path.realpath(__file__)) + "/../var/pdf.yml" + idf_file = os.path.dirname(os.path.realpath(__file__)) + "/../var/idf.yml" + nodes = [] + host_networks = {} + + with open(pdf_file) as f: + try: + pdf = yaml.safe_load(f) + except yaml.YAMLError as e: + print(e) + sys.exit(1) + + with open(idf_file) as f: + try: + idf = yaml.safe_load(f) + except yaml.YAMLError as e: + print(e) + sys.exit(1) + + valid_host = (host for host in idf['xci'][self.installer]['nodes_roles'] \ + if host in idf['xci']['flavors'][self.flavor] \ + and host != 'opnfv') + + for host in valid_host: + nodes.append(host) + hostname = idf['xci'][self.installer]['hostnames'][host] + self.add_host(hostname) + for role in idf['xci'][self.installer]['nodes_roles'][host]: + self.add_to_group(role, hostname) + + pdf_host_info = filter(lambda x: x['name'] == host, pdf['nodes'])[0] + native_vlan_if = filter(lambda x: x['vlan'] == 'native', pdf_host_info['interfaces']) + self.add_hostvar(hostname, 'ansible_host', native_vlan_if[0]['address']) + host_networks[hostname] = {} + # And now record the rest of the information + for network, ndata in idf['idf']['net_config'].items(): + network_interface_num = idf['idf']['net_config'][network]['interface'] + host_networks[hostname][network] = {} + host_networks[hostname][network]['address'] = pdf_host_info['interfaces'][int(network_interface_num)]['address'] + "/" + str(ndata['mask']) + if 'gateway' in ndata.keys(): + host_networks[hostname][network]['gateway'] = str(ndata['gateway']) + "/" + str(ndata['mask']) + + host_networks.update(self.opnfv_networks) + + self.add_groupvar('all', 'host_info', host_networks) + + # Now add the additional groups + for parent in idf['xci'][self.installer]['groups'].keys(): + map(lambda x: self.add_group(x, parent), idf['xci'][self.installer]['groups'][parent]) + + def dump(self, data): + print (json.dumps(data, sort_keys=True, indent=2)) + + def add_host(self, host): + self.inventory['all']['hosts'].append(host) + + def hosts(self): + return self.inventory['all']['hosts'] + + def add_group(self, group, parent = 'all'): + if parent not in self.inventory.keys(): + self.inventory[parent] = {} + if 'children' not in self.inventory[parent]: + self.inventory[parent]['children'] = [] + self.inventory[parent]['children'].append(group) + + def add_to_group(self, group, host): + if group not in self.inventory.keys(): + self.inventory[group] = [] + self.inventory[group].append(host) + + def add_hostvar(self, host, param, value): + if host not in self.hostvars(): + self.inventory['_meta']['hostvars'][host] = {} + self.inventory['_meta']['hostvars'][host].update({param: value}) + + def add_groupvar(self, group, param, value): + if group not in self.groupvars(group): + self.inventory[group]['vars'] = {} + self.inventory[group]['vars'].update({param: value}) + + def hostvars(self): + return iter(self.inventory['_meta']['hostvars'].keys()) + + def groupvars(self, group): + return iter(self.inventory[group]['vars'].keys()) + + def get_host_info(self, host): + return self.inventory['_meta']['hostvars'][host] + +if __name__ == '__main__': + XCIInventory() + +# vim: set ts=4 sw=4 expandtab: diff --git a/xci/playbooks/get-opnfv-scenario-requirements.yml b/xci/playbooks/get-opnfv-scenario-requirements.yml index af97ceb2..a9165709 100644 --- a/xci/playbooks/get-opnfv-scenario-requirements.yml +++ b/xci/playbooks/get-opnfv-scenario-requirements.yml @@ -31,114 +31,76 @@ loop_control: label: "{{ item[0].scenario }}" - - name: Create scenario directories - file: - path: "{{ role_path_default }}/{{ item.scenario }}" - state: directory - with_items: "{{ scenarios }}" - loop_control: - label: "{{ item.scenario }}" - - - name: Clone git repos (with git) - git: - repo: "{{ item.src }}" - dest: "{{ scenario_path_default }}/{{ item.scenario | default(item.src | basename) }}" - version: "{{ item.version | default('master') }}" - refspec: "{{ item.refspec | default(omit) }}" - update: true - force: true - when: - - item.scm == "git" or item.scm is undefined - with_items: "{{ scenarios }}" - register: git_clone - until: git_clone | success - retries: "{{ git_clone_retries }}" - delay: "{{ git_clone_retry_delay }}" + - name: Update scenarios with local overrides + set_fact: + scenarios: > + {%- for z in xci_scenarios_overrides -%} + {%- for x in scenarios if x.scenario == z.scenario -%} + {%- set _ = x.update(z) -%} + {%- endfor -%} + {%- endfor -%} + {{- scenarios -}} + with_items: "{{ xci_scenarios_overrides }}" loop_control: label: "{{ item.scenario }}" + when: xci_scenarios_overrides is defined - - name: Check that scenarios exist - stat: - path: "{{ scenario_path_default }}/{{ item.scenario }}/{{ item.role }}" - register: scenarios_list_exists + - name: Collect list of known scenarions + set_fact: + known_scenarios: > + {%- set scenario_names = [] -%} + {%- for x in scenarios -%} + {%- set _ = scenario_names.append(x.scenario) -%} + {%- endfor -%} + {{- scenario_names -}} with_items: "{{ scenarios }}" loop_control: label: "{{ item.scenario }}" - - name: Plug in the scenario to XCI - synchronize: - src: "{{ scenario_path_default }}/{{ item.item.scenario }}/{{ item.item.role }}/" - dest: "{{ role_path_default }}/{{ item.item.role | basename }}" - when: item.stat.exists - with_items: "{{ scenarios_list_exists.results }}" - loop_control: - label: "{{ item.item.scenario }}" - - - name: Synchronize local changes to scenarios' master branch - synchronize: - src: "{{ xci_path }}/xci/scenarios/{{ item.item.scenario }}/{{ item.item.role | replace('xci/scenarios/' ~ item.item.scenario ~ '/', '') }}/" - dest: "{{ role_path_default }}/{{ item.item.role | basename }}" - archive: no - times: no - recursive: yes - checksum: yes - owner: yes - group: yes - perms: yes - links: yes - failed_when: false - when: - - item.stat.exists - - item.item.version == 'master' - with_items: "{{ scenarios_list_exists.results }}" - loop_control: - label: "{{ item.item.scenario }}" + - name: Fail if 'DEPLOY_SCENARIO' is not defined + fail: + msg: "DEPLOY_SCENARIO env variable is not defined so no scenario can be deployed" + when: deploy_scenario is not defined - - name: Plug in the scenario to XCI (fallback) - synchronize: - src: "{{ xci_path }}/{{ item.item.role }}/" - dest: "{{ role_path_default }}/{{ item.item.role | basename }}" - when: not item.stat.exists - with_items: "{{ scenarios_list_exists.results }}" - loop_control: - label: "{{ item.item.scenario }}" + - name: Ensure {{ deploy_scenario }} is a known XCI scenario + fail: + msg: "{{ deploy_scenario }} does not exist" + when: deploy_scenario not in known_scenarios - - name: Gather information about the selected {{ deploy_scenario }} scenario + - name: Collect scenario information set_fact: - deploy_scenario: "{{ item }}" - with_items: "{{ scenarios }}" - loop_control: - label: "{{ item.scenario }}" - when: deploy_scenario | lower == item.scenario + xci_scenario: > + {%- set xci_scenario = {} -%} + {%- for x in scenarios if x.scenario == deploy_scenario -%} + {%- for z in x.installers if z.installer == installer_type -%} + {%- set _ = xci_scenario.update({'flavors': z.flavors}) -%} + {%- set _ = xci_scenario.update({'distros': z.distros}) -%} + {%- endfor -%} + {%- set _ = xci_scenario.update({'role': x.role | basename}) -%} + {%- endfor -%} + {{ xci_scenario }} + + - name: Ensure local facts directory exists + file: + path: "/etc/ansible/facts.d" + state: directory + become: true - - name: Determine if the selected {{ deploy_scenario }} scenario can be deployed - block: - - name: Set scenario installer fact - set_fact: - deploy_scenario_installer: "{{ item }}" - with_items: "{{ deploy_scenario.installers }}" - loop_control: - label: "{{ item.installer }}" - when: item.installer == installer_type - - name: Set scenario flavor fact - set_fact: - deploy_scenario_flavor: "{{ (xci_flavor in deploy_scenario_installer.flavors) | bool }}" - when: - - deploy_scenario_installer is defined - - deploy_scenario_installer - - name: Set scenario distro flavor fact - set_fact: - deploy_scenario_distro: "{{ (xci_distro in deploy_scenario_installer.distros) | bool }}" - when: - - deploy_scenario_flavor is defined - - deploy_scenario_flavor - when: deploy_scenario is defined + - name: Record scenario information + ini_file: + create: yes + section: scenarios + state: present + option: role + value: "{{ xci_scenario.role | basename }}" + path: "/etc/ansible/facts.d/xci.fact" + become: true - - name: Fail if {{ deploy_scenario.scenario }} is not supported + - name: Fail if {{ deploy_scenario }} is not supported fail: msg: - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - ERROR! The {{ deploy_scenario.scenario }} scenario can't be deployed. This is because + - ERROR! The {{ deploy_scenario }} scenario can't be deployed. This is because - the {{ installer_type }} XCI installer or the {{ xci_flavor }} flavor or the {{ xci_distro }} - distribution is not supported by this scenario. It may also be possible that - this scenario doesn't exist at all or it's not listed in {{ scenario_file }}. @@ -147,9 +109,32 @@ - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - '' when: - - deploy_scenario is not defined or - deploy_scenario_distro is not defined or - (deploy_scenario_distro is defined and not deploy_scenario_distro) + (xci_scenario['flavors'] is defined and xci_flavor not in xci_scenario['flavors']) or + (xci_scenario['distros'] is defined and xci_distro not in xci_scenario['distros']) + + - name: Clone git repos + git: + repo: "{{ item.src }}" + dest: "{{ scenario_path_default }}/{{ item.scenario | default(item.src | basename) }}" + version: "{{ item.version | default('master') }}" + refspec: "{{ item.refspec | default(omit) }}" + update: true + force: true + with_items: "{{ scenarios }}" + register: git_clone + until: git_clone | success + retries: "{{ git_clone_retries }}" + delay: "{{ git_clone_retry_delay }}" + loop_control: + label: "{{ item.scenario }}" + + - name: Plug in the scenario Ansible roles to XCI + synchronize: + src: "{{ scenario_path_default }}/{{ item.scenario }}/{{ item.role }}/" + dest: "{{ role_path_default }}/{{ item.role | basename }}" + with_items: "{{ scenarios }}" + loop_control: + label: "{{ item.scenario }}" vars: ansible_python_interpreter: "/usr/bin/python" diff --git a/xci/playbooks/roles/bootstrap-host/tasks/network.yml b/xci/playbooks/roles/bootstrap-host/tasks/network.yml index 92e9195e..a4f260c4 100644 --- a/xci/playbooks/roles/bootstrap-host/tasks/network.yml +++ b/xci/playbooks/roles/bootstrap-host/tasks/network.yml @@ -50,99 +50,8 @@ - name: Run handlers meta: flush_handlers -- block: - - name: configure modules - lineinfile: - dest: /etc/modules - state: present - create: yes - line: "8021q" - - name: add modules - modprobe: - name: 8021q - state: present - - name: ensure interfaces.d folder is empty - file: - state: "{{ item }}" - path: "/etc/network/interfaces.d" - with_items: - - absent - - directory - - name: ensure interfaces file is updated - template: - src: "{{ ansible_os_family | lower }}/{{ ansible_hostname }}.interface.j2" - dest: "/etc/network/interfaces" - - name: restart network service - shell: "/sbin/ifconfig {{ ansible_local.xci.network.xci_interface }} 0 && /sbin/ifdown -a && /sbin/ifup -a" - async: 15 - poll: 0 - when: ansible_os_family | lower == "debian" - -- block: - - name: Configure networking on SUSE - template: - src: "{{ ansible_os_family | lower }}/suse.interface.j2" - dest: "/etc/sysconfig/network/ifcfg-{{ item.name }}" - with_items: - - { name: "{{ ansible_local.xci.network.xci_interface }}" } - - { name: "{{ ansible_local.xci.network.xci_interface }}.10", vlan_id: 10 } - - { name: "{{ ansible_local.xci.network.xci_interface }}.30", vlan_id: 30 } - - { name: "{{ ansible_local.xci.network.xci_interface }}.20", vlan_id: 20 } - - { name: "br-mgmt", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.10", ip: "{{ host_info[inventory_hostname].MGMT_IP }}/22" } - - { name: "br-vxlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.30", ip: "{{ host_info[inventory_hostname].VXLAN_IP }}/22" } - - { name: "br-vlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}", ip: "{{ host_info[inventory_hostname].VLAN_IP }}/24" } - - { name: "br-storage", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.20", ip: "{{ host_info[inventory_hostname].STORAGE_IP }}/22" } - - - name: Add postup/postdown scripts on SUSE - copy: - src: "network-config-suse" - dest: "/etc/sysconfig/network/scripts/network-config-suse" - mode: 0755 - - - name: Configure routes on SUSE - template: - src: "{{ ansible_os_family | lower }}/suse.routes.j2" - dest: "/etc/sysconfig/network/ifroute-{{ item.name }}" - with_items: - - { name: "br-vlan", gateway: "192.168.122.1", route: "default" } - - name: restart network service - service: - name: network - state: restarted - async: 15 - poll: 0 - when: ansible_os_family | lower == "suse" - -- block: - - name: Configure networking on CentOS for interfaces - template: - src: "{{ ansible_os_family | lower }}/interface.ifcfg.j2" - dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name }}" - with_items: - - { name: "{{ ansible_local.xci.network.xci_interface }}" , bridge: "br-vlan" } - - { name: "{{ ansible_local.xci.network.xci_interface }}.10", bridge: "br-mgmt" , vlan_id: 10 } - - { name: "{{ ansible_local.xci.network.xci_interface }}.20", bridge: "br-storage", vlan_id: 20 } - - { name: "{{ ansible_local.xci.network.xci_interface }}.30", bridge: "br-vxlan" , vlan_id: 30 } - - name: Configure networking on CentOS for bridges - template: - src: "{{ ansible_os_family | lower }}/bridge.ifcfg.j2" - dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name }}" - with_items: - - { name: "br-vlan" , ip: "{{ host_info[inventory_hostname].VLAN_IP }}", prefix: 24 } - - { name: "br-mgmt" , ip: "{{ host_info[inventory_hostname].MGMT_IP }}", prefix: 22 } - - { name: "br-storage", ip: "{{ host_info[inventory_hostname].STORAGE_IP }}", prefix: 22 } - - { name: "br-vxlan" , ip: "{{ host_info[inventory_hostname].VXLAN_IP }}", prefix: 22 } - - name: Add default route through br-vlan - lineinfile: - path: "/etc/sysconfig/network-scripts/ifcfg-br-vlan" - line: "GATEWAY=192.168.122.1" - - name: restart network service - service: - name: network - state: restarted - async: 15 - poll: 0 - when: ansible_os_family | lower == "redhat" +- name: "Configure networking on {{ ansible_os_family }}" + include_tasks: "network_{{ ansible_os_family | lower }}.yml" - name: Wait for host to come back to life local_action: diff --git a/xci/playbooks/roles/bootstrap-host/tasks/network_debian.yml b/xci/playbooks/roles/bootstrap-host/tasks/network_debian.yml new file mode 100644 index 00000000..3cac1e22 --- /dev/null +++ b/xci/playbooks/roles/bootstrap-host/tasks/network_debian.yml @@ -0,0 +1,58 @@ +--- +# 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 +############################################################################## + +- name: configure modules + lineinfile: + dest: /etc/modules + state: present + create: yes + line: "8021q" + +- name: add modules + modprobe: + name: 8021q + state: present + +- name: ensure interfaces.d folder is empty + file: + state: "{{ item }}" + path: "/etc/network/interfaces.d" + with_items: + - absent + - directory + +- name: Ensure /etc/interfaces can source additional files + copy: + content: | + auto lo + iface lo inet loopback + source /etc/network/interfaces.d/*.cfg + dest: "/etc/network/interfaces" + +- name: "Configure networking for {{ inventory_hostname }}" + template: + src: "{{ installer_type }}/debian.interface.j2" + dest: "/etc/network/interfaces.d/{{ item.name }}.cfg" + with_items: + - { name: "{{ ansible_local.xci.network.xci_interface }}" } + - { name: "{{ ansible_local.xci.network.xci_interface }}.10", vlan_id: 10 } + - { name: "{{ ansible_local.xci.network.xci_interface }}.30", vlan_id: 30 } + - { name: "{{ ansible_local.xci.network.xci_interface }}.20", vlan_id: 20 } + - { name: "br-mgmt", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.10", network: "{{ host_info[inventory_hostname].admin }}" } + - { name: "br-vxlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.30", network: "{{ host_info[inventory_hostname].private }}" } + - { name: "br-vlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}", network: "{{ host_info[inventory_hostname].public }}" } + - { name: "br-storage", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.20", network: "{{ host_info[inventory_hostname].storage }}" } + loop_control: + label: "{{ item.name }}" + +- name: restart network service + shell: "/sbin/ifconfig {{ ansible_local.xci.network.xci_interface }} 0 && /sbin/ifdown -a && /sbin/ifup -a" + async: 15 + poll: 0 diff --git a/xci/playbooks/roles/bootstrap-host/tasks/network_redhat.yml b/xci/playbooks/roles/bootstrap-host/tasks/network_redhat.yml new file mode 100644 index 00000000..b06a8695 --- /dev/null +++ b/xci/playbooks/roles/bootstrap-host/tasks/network_redhat.yml @@ -0,0 +1,37 @@ +--- +# 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 +############################################################################## + +- name: "Configure networking on {{ inventory_hostname }}" + template: + src: "{{ installer_type }}/{{ ansible_os_family | lower }}.ifcfg.j2" + dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name }}" + with_items: + - { name: "{{ ansible_local.xci.network.xci_interface }}" , bridge: "br-vlan" } + - { name: "{{ ansible_local.xci.network.xci_interface }}.10", bridge: "br-mgmt" , vlan_id: 10 } + - { name: "{{ ansible_local.xci.network.xci_interface }}.20", bridge: "br-storage", vlan_id: 20 } + - { name: "{{ ansible_local.xci.network.xci_interface }}.30", bridge: "br-vxlan" , vlan_id: 30 } + - { name: "br-vlan" , network: "{{ host_info[inventory_hostname].public }}" } + - { name: "br-mgmt" , network: "{{ host_info[inventory_hostname].admin }}" } + - { name: "br-storage", network: "{{ host_info[inventory_hostname].storage }}" } + - { name: "br-vxlan" , network: "{{ host_info[inventory_hostname].private }}" } + loop_control: + label: "{{ item.name }}" + +- name: Add default route through br-vlan + lineinfile: + path: "/etc/sysconfig/network-scripts/ifcfg-br-vlan" + line: "GATEWAY={{ host_info[inventory_hostname]['public']['gateway'] | ipaddr('address') }}" + +- name: restart network service + service: + name: network + state: restarted + async: 15 + poll: 0 diff --git a/xci/playbooks/roles/bootstrap-host/tasks/network_suse.yml b/xci/playbooks/roles/bootstrap-host/tasks/network_suse.yml new file mode 100644 index 00000000..c9c9d83c --- /dev/null +++ b/xci/playbooks/roles/bootstrap-host/tasks/network_suse.yml @@ -0,0 +1,45 @@ +--- +# 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 +############################################################################## + +- name: "Configure networking on {{ inventory_hostname }}" + template: + src: "{{ installer_type }}/{{ ansible_os_family | lower }}.interface.j2" + dest: "/etc/sysconfig/network/ifcfg-{{ item.name }}" + with_items: + - { name: "{{ ansible_local.xci.network.xci_interface }}" } + - { name: "{{ ansible_local.xci.network.xci_interface }}.10", vlan_id: 10 } + - { name: "{{ ansible_local.xci.network.xci_interface }}.30", vlan_id: 30 } + - { name: "{{ ansible_local.xci.network.xci_interface }}.20", vlan_id: 20 } + - { name: "br-mgmt", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.10", network: "{{ host_info[inventory_hostname].admin }}" } + - { name: "br-vxlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.30", network: "{{ host_info[inventory_hostname].private }}" } + - { name: "br-vlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}", network: "{{ host_info[inventory_hostname].public }}" } + - { name: "br-storage", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.20", network: "{{ host_info[inventory_hostname].storage }}" } + loop_control: + label: "{{ item.name }}" + +- name: Add postup/postdown scripts on SUSE + copy: + src: "network-config-suse" + dest: "/etc/sysconfig/network/scripts/network-config-suse" + mode: 0755 + +- name: Configure routes on SUSE + template: + src: "{{ installer_type }}/{{ ansible_os_family | lower }}.routes.j2" + dest: "/etc/sysconfig/network/ifroute-{{ item.name }}" + with_items: + - { name: "br-vlan", gateway: "{{ host_info[inventory_hostname]['public']['gateway'] }}", route: "default" } + +- name: restart network service + service: + name: network + state: restarted + async: 15 + poll: 0 diff --git a/xci/playbooks/roles/bootstrap-host/templates/debian/compute00.interface.j2 b/xci/playbooks/roles/bootstrap-host/templates/debian/compute00.interface.j2 deleted file mode 100644 index 2da12f20..00000000 --- a/xci/playbooks/roles/bootstrap-host/templates/debian/compute00.interface.j2 +++ /dev/null @@ -1,75 +0,0 @@ -# {{ ansible_managed }} - -# The loopback network interface -auto lo -iface lo inet loopback - -# Physical interface -auto {{ ansible_default_ipv4.interface }} -iface {{ ansible_default_ipv4.interface }} inet manual - -# Container/Host management VLAN interface -auto {{ ansible_default_ipv4.interface }}.10 -iface {{ ansible_default_ipv4.interface }}.10 inet manual - vlan-raw-device {{ ansible_default_ipv4.interface }} - -# OpenStack Networking VXLAN (tunnel/overlay) VLAN interface -auto {{ ansible_default_ipv4.interface }}.30 -iface {{ ansible_default_ipv4.interface }}.30 inet manual - vlan-raw-device {{ ansible_default_ipv4.interface }} - -# Storage network VLAN interface -auto {{ ansible_default_ipv4.interface }}.20 -iface {{ ansible_default_ipv4.interface }}.20 inet manual - vlan-raw-device {{ ansible_default_ipv4.interface }} - -# Container/Host management bridge -auto br-mgmt -iface br-mgmt inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }}.10 - address {{host_info[inventory_hostname].MGMT_IP}} - netmask 255.255.252.0 - -# compute1 VXLAN (tunnel/overlay) bridge config -auto br-vxlan -iface br-vxlan inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }}.30 - address {{host_info[inventory_hostname].VXLAN_IP}} - netmask 255.255.252.0 - -# OpenStack Networking VLAN bridge -auto br-vlan -iface br-vlan inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }} - address {{host_info[inventory_hostname].VLAN_IP}} - netmask 255.255.255.0 - gateway 192.168.122.1 - dns-nameserver 8.8.8.8 8.8.4.4 - offload-sg off - # Create veth pair, don't bomb if already exists - pre-up ip link add br-vlan-veth type veth peer name eth12 || true - # Set both ends UP - pre-up ip link set br-vlan-veth up - pre-up ip link set eth12 up - # Delete veth pair on DOWN - post-down ip link del br-vlan-veth || true - bridge_ports br-vlan-veth - -# OpenStack Storage bridge -auto br-storage -iface br-storage inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }}.20 - address {{host_info[inventory_hostname].STORAGE_IP}} - netmask 255.255.252.0 diff --git a/xci/playbooks/roles/bootstrap-host/templates/debian/compute01.interface.j2 b/xci/playbooks/roles/bootstrap-host/templates/debian/compute01.interface.j2 deleted file mode 120000 index a74df1c2..00000000 --- a/xci/playbooks/roles/bootstrap-host/templates/debian/compute01.interface.j2 +++ /dev/null @@ -1 +0,0 @@ -compute00.interface.j2
\ No newline at end of file diff --git a/xci/playbooks/roles/bootstrap-host/templates/debian/controller00.interface.j2 b/xci/playbooks/roles/bootstrap-host/templates/debian/controller00.interface.j2 deleted file mode 100644 index c540f66e..00000000 --- a/xci/playbooks/roles/bootstrap-host/templates/debian/controller00.interface.j2 +++ /dev/null @@ -1,74 +0,0 @@ -# {{ ansible_managed }} - -# The loopback network interface -auto lo -iface lo inet loopback - -# Physical interface -auto {{ ansible_default_ipv4.interface }} -iface {{ ansible_default_ipv4.interface }} inet manual - -# Container/Host management VLAN interface -auto {{ ansible_default_ipv4.interface }}.10 -iface {{ ansible_default_ipv4.interface }}.10 inet manual - vlan-raw-device {{ ansible_default_ipv4.interface }} - -# OpenStack Networking VXLAN (tunnel/overlay) VLAN interface -auto {{ ansible_default_ipv4.interface }}.30 -iface {{ ansible_default_ipv4.interface }}.30 inet manual - vlan-raw-device {{ ansible_default_ipv4.interface }} - -# Storage network VLAN interface (optional) -auto {{ ansible_default_ipv4.interface }}.20 -iface {{ ansible_default_ipv4.interface }}.20 inet manual - vlan-raw-device {{ ansible_default_ipv4.interface }} - -# Container/Host management bridge -auto br-mgmt -iface br-mgmt inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }}.10 - address {{host_info[inventory_hostname].MGMT_IP}} - netmask 255.255.252.0 - -# OpenStack Networking VXLAN (tunnel/overlay) bridge -auto br-vxlan -iface br-vxlan inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }}.30 - address {{host_info[inventory_hostname].VXLAN_IP}} - netmask 255.255.252.0 - -# OpenStack Networking VLAN bridge -auto br-vlan -iface br-vlan inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }} - address {{host_info[inventory_hostname].VLAN_IP}} - netmask 255.255.255.0 - gateway 192.168.122.1 - dns-nameserver 8.8.8.8 8.8.4.4 - # Create veth pair, don't bomb if already exists - pre-up ip link add br-vlan-veth type veth peer name eth12 || true - # Set both ends UP - pre-up ip link set br-vlan-veth up - pre-up ip link set eth12 up - # Delete veth pair on DOWN - post-down ip link del br-vlan-veth || true - bridge_ports br-vlan-veth - -# OpenStack Storage bridge -auto br-storage -iface br-storage inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }}.20 - address {{host_info[inventory_hostname].STORAGE_IP}} - netmask 255.255.252.0 diff --git a/xci/playbooks/roles/bootstrap-host/templates/debian/controller01.interface.j2 b/xci/playbooks/roles/bootstrap-host/templates/debian/controller01.interface.j2 deleted file mode 120000 index e835d7ca..00000000 --- a/xci/playbooks/roles/bootstrap-host/templates/debian/controller01.interface.j2 +++ /dev/null @@ -1 +0,0 @@ -controller00.interface.j2
\ No newline at end of file diff --git a/xci/playbooks/roles/bootstrap-host/templates/debian/controller02.interface.j2 b/xci/playbooks/roles/bootstrap-host/templates/debian/controller02.interface.j2 deleted file mode 120000 index e835d7ca..00000000 --- a/xci/playbooks/roles/bootstrap-host/templates/debian/controller02.interface.j2 +++ /dev/null @@ -1 +0,0 @@ -controller00.interface.j2
\ No newline at end of file diff --git a/xci/playbooks/roles/bootstrap-host/templates/debian/opnfv.interface.j2 b/xci/playbooks/roles/bootstrap-host/templates/debian/opnfv.interface.j2 deleted file mode 100644 index 03f81dbb..00000000 --- a/xci/playbooks/roles/bootstrap-host/templates/debian/opnfv.interface.j2 +++ /dev/null @@ -1,66 +0,0 @@ -# {{ ansible_managed }} - -# The loopback network interface -auto lo -iface lo inet loopback - -# Physical interface -auto {{ ansible_default_ipv4.interface }} -iface {{ ansible_default_ipv4.interface }} inet manual - -# Container/Host management VLAN interface -auto {{ ansible_default_ipv4.interface }}.10 -iface {{ ansible_default_ipv4.interface }}.10 inet manual - vlan-raw-device {{ ansible_default_ipv4.interface }} - -# OpenStack Networking VXLAN (tunnel/overlay) VLAN interface -auto {{ ansible_default_ipv4.interface }}.30 -iface {{ ansible_default_ipv4.interface }}.30 inet manual - vlan-raw-device {{ ansible_default_ipv4.interface }} - -# Storage network VLAN interface (optional) -auto {{ ansible_default_ipv4.interface }}.20 -iface {{ ansible_default_ipv4.interface }}.20 inet manual - vlan-raw-device {{ ansible_default_ipv4.interface }} - -# Container/Host management bridge -auto br-mgmt -iface br-mgmt inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }}.10 - address {{host_info[inventory_hostname].MGMT_IP}} - netmask 255.255.252.0 - -# OpenStack Networking VXLAN (tunnel/overlay) bridge -auto br-vxlan -iface br-vxlan inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }}.30 - address {{ host_info[inventory_hostname].VXLAN_IP }} - netmask 255.255.252.0 - -# OpenStack Networking VLAN bridge -auto br-vlan -iface br-vlan inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }} - address {{host_info[inventory_hostname].VLAN_IP}} - netmask 255.255.255.0 - gateway 192.168.122.1 - dns-nameserver 8.8.8.8 8.8.4.4 - -# OpenStack Storage bridge -auto br-storage -iface br-storage inet static - bridge_stp off - bridge_waitport 0 - bridge_fd 0 - bridge_ports {{ ansible_default_ipv4.interface }}.20 - address {{host_info[inventory_hostname].STORAGE_IP}} - netmask 255.255.252.0 diff --git a/xci/playbooks/roles/bootstrap-host/templates/osa/debian.interface.j2 b/xci/playbooks/roles/bootstrap-host/templates/osa/debian.interface.j2 new file mode 100644 index 00000000..3eddce45 --- /dev/null +++ b/xci/playbooks/roles/bootstrap-host/templates/osa/debian.interface.j2 @@ -0,0 +1,36 @@ +# {{ ansible_managed }} + +# Physical interface +{% if item.bridge_ports is not defined %} +auto {{ item.name }} +iface {{ item.name }} inet manual +{% if item.vlan_id is defined %} + vlan-raw-device {{ item.name|replace('.' ~ item.vlan_id, '') }} +{% endif %} + +{% else %} +auto {{ item.name }} +iface {{ item.name }} inet static + bridge_stp off + bridge_waitport 0 + bridge_fd 0 + bridge_ports {{ item.bridge_ports }} +{% if item.name == 'br-vlan' %} + # Create veth pair, don't bomb if already exists + pre-up ip link add br-vlan-veth type veth peer name eth12 || true + # Set both ends UP + pre-up ip link set br-vlan-veth up + pre-up ip link set eth12 up + # Delete veth pair on DOWN + post-down ip link del br-vlan-veth || true + bridge_ports br-vlan-veth +{% endif %} +{% if item.network is defined %} + address {{ item.network.address | ipaddr('address') }} + netmask {{ item.network.address | ipaddr('netmask') }} +{% endif %} +{% if item.network is defined and item.network.gateway is defined %} + gateway {{ item.network.gateway | ipaddr('address') }} +{% endif %} + +{% endif %} diff --git a/xci/playbooks/roles/bootstrap-host/templates/osa/redhat.interface.j2 b/xci/playbooks/roles/bootstrap-host/templates/osa/redhat.interface.j2 new file mode 100644 index 00000000..fa957764 --- /dev/null +++ b/xci/playbooks/roles/bootstrap-host/templates/osa/redhat.interface.j2 @@ -0,0 +1,19 @@ +DEVICE={{ item.name }} +NM_CONTROLLED=no +ONBOOT=yes +BOOTPROTO=none +{% if item.vlan_id is defined %} +VLAN=yes +ETHERDEVICE={{ ansible_local.xci.network.xci_interface }} +VLAN_ID={{ item.vlan_id }} +{% endif %} +{% if item.bridge is not defined %} +BRIDGE={{ item.bridge }} +{% else %} +TYPE=Bridge +DELAY=0 +STP=off +{% endif %} +{% if item.network is defined %} +IPADDR={{ item.network.address }} +{% endif %} diff --git a/xci/playbooks/roles/bootstrap-host/templates/suse/suse.interface.j2 b/xci/playbooks/roles/bootstrap-host/templates/osa/suse.interface.j2 index 27b01eb4..70811a09 100644 --- a/xci/playbooks/roles/bootstrap-host/templates/suse/suse.interface.j2 +++ b/xci/playbooks/roles/bootstrap-host/templates/osa/suse.interface.j2 @@ -10,8 +10,8 @@ BRIDGE_FORWARDDELAY='0' BRIDGE_STP=off BRIDGE_PORTS={{ item.bridge_ports }} {% endif %} -{% if item.ip is defined %} -IPADDR={{ item.ip }} +{% if item.network is defined %} +IPADDR={{ item.network.address }} {% endif %} PRE_UP_SCRIPT="compat:suse:network-config-suse" POST_DOWN_SCRIPT="compat:suse:network-config-suse" diff --git a/xci/playbooks/roles/bootstrap-host/templates/osa/suse.routes.j2 b/xci/playbooks/roles/bootstrap-host/templates/osa/suse.routes.j2 new file mode 100644 index 00000000..93941fad --- /dev/null +++ b/xci/playbooks/roles/bootstrap-host/templates/osa/suse.routes.j2 @@ -0,0 +1 @@ +{{ item.route }} {{ item.gateway | ipaddr('address') }} diff --git a/xci/playbooks/roles/bootstrap-host/templates/redhat/bridge.ifcfg.j2 b/xci/playbooks/roles/bootstrap-host/templates/redhat/bridge.ifcfg.j2 deleted file mode 100644 index 06b5f177..00000000 --- a/xci/playbooks/roles/bootstrap-host/templates/redhat/bridge.ifcfg.j2 +++ /dev/null @@ -1,9 +0,0 @@ -DEVICE={{ item.name }} -NM_CONTROLLED=no -IPADDR={{ item.ip }} -PREFIX={{ item.prefix }} -ONBOOT=yes -BOOTPROTO=none -TYPE=Bridge -DELAY=0 -STP=off diff --git a/xci/playbooks/roles/bootstrap-host/templates/redhat/interface.ifcfg.j2 b/xci/playbooks/roles/bootstrap-host/templates/redhat/interface.ifcfg.j2 deleted file mode 100644 index a97ad0cf..00000000 --- a/xci/playbooks/roles/bootstrap-host/templates/redhat/interface.ifcfg.j2 +++ /dev/null @@ -1,10 +0,0 @@ -DEVICE={{ item.name }} -NM_CONTROLLED=no -ONBOOT=yes -BOOTPROTO=none -{% if item.vlan_id is defined %} -VLAN=yes -ETHERDEVICE={{ ansible_default_ipv4.interface }} -VLAN_ID={{ item.vlan_id }} -{% endif %} -BRIDGE={{ item.bridge }} diff --git a/xci/playbooks/roles/bootstrap-host/templates/suse/suse.routes.j2 b/xci/playbooks/roles/bootstrap-host/templates/suse/suse.routes.j2 deleted file mode 100644 index 7c868447..00000000 --- a/xci/playbooks/roles/bootstrap-host/templates/suse/suse.routes.j2 +++ /dev/null @@ -1 +0,0 @@ -{{ item.route }} {{ item.gateway }} |