Introduce Centos7 support

This change introduces Centos7 support to engine using the default
scenario k8-calico-nofeature.

The distro to provision the machines with can be set by using -o
parameter of deploy.sh and it can either be ubuntu1804 or centos7.
If it is not specified, it will be set to ubuntu1804 by default.

Please note that only the default scenario, k8-calico-nofeature is
verified on centos7 so only this scenario is updated with centos7
in sdf.yml. The other scenarios will be updated once they are
verified on centos7. Apart from that, sdf.yml is updated with the
new name for the distro - previously it was only ubuntu and now
it is ubuntu1804.

DIB related parameters are also controlled by the distro setting now
and right dib_os_release and dib_os_element are set accordingly without
needing to set them manually.

Deployment image build using dib also depends on the variable
use_prebuilt_deployment_image now. If this variable is set to true like
how we are doing within CI, create_image_via_dib will be set to false.
Since use_prebuilt_deployment_image is set to false by default,
create_image_via_dib value will be set to true automatically for the
users who might be using the engine manually.

We also stopped calling out distro names for node configuration explicitly
and instead use ansible_os_family as we support one of each from debian
and rhel.

Change-Id: Ic951de6cf560d64630b72bd5727edafd9fb582bf
diff --git a/playbooks/roles/configure-targethosts/tasks/configure-network-ubuntu16.yml b/playbooks/roles/configure-targethosts/tasks/configure-network-Debian.yml
similarity index 98%
rename from playbooks/roles/configure-targethosts/tasks/configure-network-ubuntu16.yml
rename to playbooks/roles/configure-targethosts/tasks/configure-network-Debian.yml
index b47f3b4..ac9a9ff 100644
--- a/playbooks/roles/configure-targethosts/tasks/configure-network-ubuntu16.yml
+++ b/playbooks/roles/configure-targethosts/tasks/configure-network-Debian.yml
@@ -61,7 +61,7 @@
 
 - name: Configure networking for host
   template:
-    src: "{{ distribution }}.interface.j2"
+    src: "{{ ansible_os_family }}.interface.j2"
     dest: "/etc/network/interfaces.d/{{ item.value }}.cfg"
   loop: "{{ if_mac_dict | dict2items }}"
 
diff --git a/playbooks/roles/configure-targethosts/tasks/configure-network-RedHat.yml b/playbooks/roles/configure-targethosts/tasks/configure-network-RedHat.yml
new file mode 100644
index 0000000..729fed8
--- /dev/null
+++ b/playbooks/roles/configure-targethosts/tasks/configure-network-RedHat.yml
@@ -0,0 +1,56 @@
+---
+# ============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: Configure modules
+  lineinfile:
+    dest: /etc/modules
+    state: present
+    create: yes
+    line: "8021q"
+
+- name: Add modules
+  modprobe:
+    name: 8021q
+    state: present
+
+- name: Compute mapping dict from mac address to device name
+  set_fact:
+    device_mac_dict: "{{ (device_mac_dict | default({})) | combine({item.macaddress: item.device}) }}"
+  with_items:
+    - "{{ ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') | map('extract', hostvars[inventory_hostname]) |  selectattr('macaddress','defined') | list }}"
+
+- name: Compute mapping dict from mac address to interface name (device name with/without VLAN info)
+  set_fact:
+    if_mac_dict: "{{ ( if_mac_dict | default({}) ) | combine({item.mac_address: (item.vlan == 'native') | ternary(device_mac_dict[item.mac_address], device_mac_dict[item.mac_address] + '.' + item.vlan) }) }}"
+  with_items:
+    - "{{ node.interfaces }}"
+
+- name: Configure networking for host
+  template:
+    src: "{{ ansible_os_family }}.interface.j2"
+    dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.value }}"
+  with_items:
+    - "{{ if_mac_dict | dict2items }}"
+
+- name: Restart network
+  service:
+    name: network
+    state: restarted
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/configure-targethosts/tasks/configure-network-ubuntu18.yml b/playbooks/roles/configure-targethosts/tasks/configure-network-ubuntu18.yml
deleted file mode 120000
index d1ff29d..0000000
--- a/playbooks/roles/configure-targethosts/tasks/configure-network-ubuntu18.yml
+++ /dev/null
@@ -1 +0,0 @@
-configure-network-ubuntu16.yml
\ No newline at end of file
diff --git a/playbooks/roles/configure-targethosts/tasks/configure-network.yml b/playbooks/roles/configure-targethosts/tasks/configure-network.yml
index 3fb9b99..d5b78f8 100644
--- a/playbooks/roles/configure-targethosts/tasks/configure-network.yml
+++ b/playbooks/roles/configure-targethosts/tasks/configure-network.yml
@@ -26,14 +26,13 @@
 - name: Set facts for the node "{{ node_name }}"
   set_fact:
     node: "{{ nodes | selectattr('name', 'equalto', node_name) | first }}"
-    distribution: "{{ ansible_distribution | lower }}{{ ansible_distribution_major_version }}"
 
 - name: Ensure glean rules are removed
   file:
     path: "/etc/udev/rules.d/99-glean.rules"
     state: absent
 
-- name: Configure networking for {{ distribution }}
-  include_tasks: "configure-network-{{ distribution }}.yml"
+- name: Configure networking for {{ ansible_os_family }}
+  include_tasks: "configure-network-{{ ansible_os_family }}.yml"
 
 # vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/configure-targethosts/tasks/install-packages-ubuntu16.yml b/playbooks/roles/configure-targethosts/tasks/install-packages-Debian.yml
similarity index 100%
rename from playbooks/roles/configure-targethosts/tasks/install-packages-ubuntu16.yml
rename to playbooks/roles/configure-targethosts/tasks/install-packages-Debian.yml
diff --git a/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml b/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml
new file mode 100644
index 0000000..95e9af3
--- /dev/null
+++ b/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml
@@ -0,0 +1,44 @@
+---
+# ============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: Install packages
+  action: >
+    {{ ansible_pkg_mgr }} name={{ item }} state=present update_cache=yes
+  with_items:
+    - "yum-utils"
+    - "device-mapper-persistent-data"
+    - "lvm2"
+    - "ca-certificates"
+    - "curl"
+    - "chrony"
+    - "dbus"
+
+- name: Add docker-ce yum repository
+  command: "yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo"
+  register: yumcfg_status
+  become: yes
+
+- name: Install docker
+  action: >
+    {{ ansible_pkg_mgr }} name={{ item }} state=present update_cache=yes
+  with_items:
+    - "docker-ce"
+    - "docker-ce-cli"
+    - "containerd.io"
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/configure-targethosts/tasks/install-packages-ubuntu18.yml b/playbooks/roles/configure-targethosts/tasks/install-packages-ubuntu18.yml
deleted file mode 120000
index 30a7101..0000000
--- a/playbooks/roles/configure-targethosts/tasks/install-packages-ubuntu18.yml
+++ /dev/null
@@ -1 +0,0 @@
-install-packages-ubuntu16.yml
\ No newline at end of file
diff --git a/playbooks/roles/configure-targethosts/tasks/install-packages.yml b/playbooks/roles/configure-targethosts/tasks/install-packages.yml
index 68b4b1a..2ea2322 100644
--- a/playbooks/roles/configure-targethosts/tasks/install-packages.yml
+++ b/playbooks/roles/configure-targethosts/tasks/install-packages.yml
@@ -17,11 +17,7 @@
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
 
-- name: Set distribution
-  set_fact:
-    distribution: "{{ ansible_distribution | lower }}{{ ansible_distribution_major_version }}"
-
-- name: Install packages on {{ distribution }}
-  include_tasks: "install-packages-{{ distribution }}.yml"
+- name: Install packages on {{ ansible_os_family }}
+  include_tasks: "install-packages-{{ ansible_os_family }}.yml"
 
 # vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/configure-targethosts/templates/ubuntu16.interface.j2 b/playbooks/roles/configure-targethosts/templates/Debian.interface.j2
similarity index 100%
rename from playbooks/roles/configure-targethosts/templates/ubuntu16.interface.j2
rename to playbooks/roles/configure-targethosts/templates/Debian.interface.j2
diff --git a/playbooks/roles/configure-targethosts/templates/RedHat.interface.j2 b/playbooks/roles/configure-targethosts/templates/RedHat.interface.j2
new file mode 100644
index 0000000..a2f7f0e
--- /dev/null
+++ b/playbooks/roles/configure-targethosts/templates/RedHat.interface.j2
@@ -0,0 +1,25 @@
+{%- set macaddress = item.key -%}
+{%- set device = item.value -%}
+{%- for selected_net_name, selected_net in idf.net_config.iteritems() if node.interfaces[selected_net.interface].mac_address == macaddress -%}
+{%- set selected_inf = node.interfaces[selected_net.interface] -%}
+TYPE=Ethernet
+DEVICE={{ device }}
+ONBOOT=yes
+HWADDR={{ macaddress }}
+{% if selected_inf.address == "dhcp" %}
+BOOTPROTO=dhcp
+{% elif selected_inf.address != "manual" %}
+BOOTPROTO=none
+IPADDR={{ selected_inf.address | ipaddr('address') }}
+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.dns is defined %}
+{% for dns in selected_net.dns %}
+DNS{{ loop.index0 }}={{ dns }}
+{% endfor %}
+{% endif %}
+
+{%- endfor -%}
diff --git a/playbooks/roles/configure-targethosts/templates/centos7.interface.j2 b/playbooks/roles/configure-targethosts/templates/centos7.interface.j2
deleted file mode 100644
index 48cdce8..0000000
--- a/playbooks/roles/configure-targethosts/templates/centos7.interface.j2
+++ /dev/null
@@ -1 +0,0 @@
-placeholder
diff --git a/playbooks/roles/configure-targethosts/templates/ubuntu18.interface.j2 b/playbooks/roles/configure-targethosts/templates/ubuntu18.interface.j2
deleted file mode 120000
index 92d7698..0000000
--- a/playbooks/roles/configure-targethosts/templates/ubuntu18.interface.j2
+++ /dev/null
@@ -1 +0,0 @@
-ubuntu16.interface.j2
\ No newline at end of file
diff --git a/playbooks/roles/post-deployment/tasks/install-packages-ubuntu16.yml b/playbooks/roles/post-deployment/tasks/install-packages-Debian.yml
similarity index 100%
rename from playbooks/roles/post-deployment/tasks/install-packages-ubuntu16.yml
rename to playbooks/roles/post-deployment/tasks/install-packages-Debian.yml
diff --git a/playbooks/roles/post-deployment/tasks/install-packages-RedHat.yml b/playbooks/roles/post-deployment/tasks/install-packages-RedHat.yml
new file mode 100644
index 0000000..9386a89
--- /dev/null
+++ b/playbooks/roles/post-deployment/tasks/install-packages-RedHat.yml
@@ -0,0 +1,37 @@
+---
+# ============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: Add google kubernetes repository
+  yum_repository:
+    name: Kubernetes
+    description: Google Kubernetes yum repository
+    baseurl: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
+    enabled: yes
+  become: yes
+
+- name: Add google kubernetes yum repository
+  command: "yum-config-manager --add-repo https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 --nogpgcheck"
+  register: yumcfg_status
+  become: yes
+
+- name: Add google kubernetes yum repository
+  command: "yum install -y --nogpgcheck kubectl"
+  register: yumpkg_status
+  become: yes
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/post-deployment/tasks/main.yml b/playbooks/roles/post-deployment/tasks/main.yml
index b7baa42..ce8caf8 100644
--- a/playbooks/roles/post-deployment/tasks/main.yml
+++ b/playbooks/roles/post-deployment/tasks/main.yml
@@ -17,12 +17,8 @@
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
 
-- name: Set distribution
-  set_fact:
-    distribution: "{{ ansible_distribution | lower }}{{ ansible_distribution_major_version }}"
-
-- name: Install packages on {{ distribution }}
-  include_tasks: "install-packages-{{ distribution }}.yml"
+- name: Install packages on {{ ansible_os_family }}
+  include_tasks: "install-packages-{{ ansible_os_family }}.yml"
 
 - name: Ensure /home/{{ ansible_env.SUDO_USER }}/.kube folder exists and empty
   file: