summaryrefslogtreecommitdiffstats
path: root/playbooks/roles
diff options
context:
space:
mode:
authorRihab Banday <rihab.banday@ericsson.com>2021-05-31 20:23:21 +0200
committerRihab Banday <rihab.banday@ericsson.com>2021-09-01 15:03:29 +0000
commitbc1786a24447121b5005492aaea8ca786135be29 (patch)
treecd6ced17b39538afc2bb97c733bf9a18560af5c5 /playbooks/roles
parent3fe71dc93fb81199401f921c10d4fe6220aa7175 (diff)
Add initial config to support deployments on VMs
* Add initial version of PDF and IDF that will be consumed by the hardware provisioner used in Kuberef to bring up libvirt VMs (for now 2 VMs for dev purposes). * Add deploy_on_vms.sh script to deploy Kuberef on VMs * Add new functions referenced by the deploy_on_vms.sh script - these can be merged with existing functions * Modify some of te BMRA templates to accomodate new changes. This has been tested on Ubuntu 18.04 baremetal server. Change-Id: I95a5e85cdab95befd24a1cae9f367b32ce26621e Signed-off-by: Rihab Banday <rihab.banday@ericsson.com> Reviewed-on: https://gerrit.opnfv.org/gerrit/c/kuberef/+/72621 Tested-by: jenkins-ci <jenkins-opnfv-ci@opnfv.org> Reviewed-by: Michael Pedersen <michaelx.pedersen@intel.com> Reviewed-by: Georg Kunz <georg.kunz@ericsson.com>
Diffstat (limited to 'playbooks/roles')
-rw-r--r--playbooks/roles/bmra-config/templates/inventory.j22
-rw-r--r--playbooks/roles/configure-vms/tasks/main.yaml91
-rw-r--r--playbooks/roles/configure-vms/templates/Debian.interface.j233
3 files changed, 125 insertions, 1 deletions
diff --git a/playbooks/roles/bmra-config/templates/inventory.j2 b/playbooks/roles/bmra-config/templates/inventory.j2
index 9b91c5f..f22aa56 100644
--- a/playbooks/roles/bmra-config/templates/inventory.j2
+++ b/playbooks/roles/bmra-config/templates/inventory.j2
@@ -6,7 +6,7 @@ SPDX-License-Identifier: Apache-2.0
[all]
{% for node in nodes %}
-{{ idf.kubespray.hostnames[node.name] }} ansible_host={{ node.interfaces[idf.net_config[engine.pxe_network].interface].address }} ip={{ node.interfaces[idf.net_config[engine.pxe_network].interface].address }}
+{{ idf.kubespray.hostnames[node.name] }} ansible_host={{ node.interfaces[idf.net_config[engine.pxe_network].interface].address }} ip={{ node.interfaces[idf.net_config[engine.pxe_network].interface].address }} {% if vendor|lower == 'libvirt-vms' %} ansible_user=root {% endif %}{{''}}
{% endfor %}
localhost ansible_connection=local ansible_python_interpreter=/usr/bin/python2
diff --git a/playbooks/roles/configure-vms/tasks/main.yaml b/playbooks/roles/configure-vms/tasks/main.yaml
new file mode 100644
index 0000000..ee90782
--- /dev/null
+++ b/playbooks/roles/configure-vms/tasks/main.yaml
@@ -0,0 +1,91 @@
+---
+# ============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: Get node names from IDF
+ set_fact:
+ node_name: "{{ item.key }}"
+ with_dict: "{{ idf.kubespray.hostnames }}"
+ when: item.value == inventory_hostname
+
+- name: Set facts for the nodes
+ set_fact:
+ node: "{{ nodes | selectattr('name', 'equalto', node_name) | first }}"
+
+- name: Configure modules
+ lineinfile:
+ dest: /etc/modules
+ state: present
+ create: true
+ 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: Compute mapping dict from mac address to device name
+ set_fact:
+ device_mac_dict: "{{ (device_mac_dict | default({})) | combine({item.macaddress: item.device}) }}"
+ loop: |-
+ {{ ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') |
+ map('extract', hostvars[inventory_hostname]) | selectattr('macaddress','defined') | list }}
+ when: "'.' not in item.device"
+
+- name: Filter to include only configured ethernet interfaces
+ set_fact:
+ if_mac_dict: "{{ ( if_mac_dict | default({}) ) | combine({item.mac_address: device_mac_dict[item.mac_address]}) }}"
+ loop: "{{ node.interfaces }}"
+
+- name: Configure networking for host
+ template:
+ src: "Debian.interface.j2"
+ dest: "/etc/network/interfaces.d/{{ item.value }}.cfg"
+ loop: "{{ if_mac_dict | dict2items }}"
+
+- name: Reboot the machine
+ shell: "sleep 5 && reboot"
+ async: 1
+ poll: 0
+ changed_when: false
+
+- name: Wait for host to come back to life
+ wait_for_connection:
+ connect_timeout: 10
+ sleep: 5
+ delay: 120
+ timeout: 300
+ register: result
+ until: result is succeeded
+ retries: 3
diff --git a/playbooks/roles/configure-vms/templates/Debian.interface.j2 b/playbooks/roles/configure-vms/templates/Debian.interface.j2
new file mode 100644
index 0000000..ef1a9fd
--- /dev/null
+++ b/playbooks/roles/configure-vms/templates/Debian.interface.j2
@@ -0,0 +1,33 @@
+{%- set macaddress = item.key -%}
+{%- set device = item.value -%}
+{%- for selected_net_name, selected_net in idf.net_config.items() if node.interfaces[selected_net.interface].mac_address == macaddress -%}
+{%- set selected_inf = node.interfaces[selected_net.interface] -%}
+{%- set ifname = device if selected_inf.vlan == 'native' else device + '.' + selected_inf.vlan -%}
+{%- set proto = "inet6" if selected_net.network | ipv6 else "inet" -%}
+{%- set method = selected_inf.address if selected_inf.address in ["dhcp", "manual"] else "static" -%}
+
+auto {{ ifname }}
+iface {{ ifname }} {{ proto }} {{ method }}
+{% if selected_net.gateway is defined %}
+up route add default gateway {{ selected_net.gateway | ipaddr('address') }}
+{% endif %}
+{% if method != "manual" %}
+address {{ selected_inf.address | ipaddr('address') }}
+{% endif %}
+{% if selected_inf.address | ipv6 %}
+netmask {{ selected_net.mask }}
+{% endif %}
+{% if selected_inf.address | ipv4 %}
+netmask {{ (selected_net.network + "/" + (selected_net.mask | string)) | ipaddr('netmask') }}
+{% endif %}
+{% if selected_net.gateway is defined %}
+gateway {{ selected_net.gateway | ipaddr('address') }}
+{% endif %}
+{% if selected_net.routes is defined %}
+{% for route in selected_net.routes %}
+up route add -net {{ route.network }}/{{ route.mask }} gw {{ route.gateway }}
+{% endfor %}
+{% endif %}
+
+{%- endfor -%}
+