Prepare for offline deployment in kolla

installer-type: kolla
deploy-scenario: os-nosdn-nofeature

Change-Id: I6c0dd0e4af1c79fb48fcba3278f05f97c4eefd45
diff --git a/playbooks/roles/configure-targethosts/tasks/configure-offline-deployment.yaml b/playbooks/roles/configure-targethosts/tasks/configure-offline-deployment.yaml
new file mode 100644
index 0000000..dec80b9
--- /dev/null
+++ b/playbooks/roles/configure-targethosts/tasks/configure-offline-deployment.yaml
@@ -0,0 +1,65 @@
+---
+# ============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: Config docker proxy
+  block:
+    - name: Check that /etc/systemd/system/docker.service.d exists
+      stat:
+        path: "/etc/systemd/system/docker.service.d"
+      register: dir_stats
+
+    - name: Create /etc/systemd/system/docker.service.d if not exists
+      file:
+        path: "/etc/systemd/system/docker.service.d"
+        state: directory
+      when: not dir_stats.stat.exists
+
+    - name: Create proxy conf file under /etc/systemd/system/docker.service.d/
+      file:
+        path: "/etc/systemd/system/docker.service.d/http-proxy.conf"
+        state: touch
+
+    - name: Config docker proxy in http-proxy.conf
+      blockinfile:
+        dest: "/etc/systemd/system/docker.service.d/http-proxy.conf"
+        block: |
+          [Service]
+          Environment="HTTP_PROXY={{ idf.proxy_settings.http_proxy }}"
+          Environment="HTTPS_PROXY={{ idf.proxy_settings.https_proxy }}"
+          Environment="NO_PROXY={{ idf.proxy_settings.no_proxy }}"
+  when:
+    idf.proxy_settings is defined
+
+- name: Install packages on {{ ansible_os_family }}
+  include_tasks: "install-packages-{{ ansible_os_family }}.yml"
+
+- name: Create folder to store self-signed certificates for docker client
+  file:
+    path: "/etc/docker/certs.d/{{ server_fqdn }}"
+    state: "{{ item }}"
+  with_items:
+    - absent
+    - directory
+
+- name: Copy self-signed certificate
+  copy:
+    src: "{{ engine_cache }}/certs/ca.crt"
+    dest: "/etc/docker/certs.d/{{ server_fqdn }}"
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/configure-targethosts/tasks/configure-online-deployment.yaml b/playbooks/roles/configure-targethosts/tasks/configure-online-deployment.yaml
new file mode 100644
index 0000000..0ad0ae6
--- /dev/null
+++ b/playbooks/roles/configure-targethosts/tasks/configure-online-deployment.yaml
@@ -0,0 +1,75 @@
+---
+# ============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=========================================================
+
+# NOTE (fdegir): gpg-agent is required for being able to run apt-key add
+- name: Install gpg-agent
+  apt:
+    name: gpg-agent
+    state: present
+    update_cache: true
+
+- name: Add docker apt key
+  apt_key:
+    url: https://download.docker.com/linux/ubuntu/gpg
+    state: present
+
+# NOTE(fdegir): ansible apt_repository gives segmentation fault so failling back to command
+- name: Add docker apt repository
+  command: |-
+    add-apt-repository \
+    "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
+  changed_when: false
+
+- name: Run apt update
+  apt:
+    update_cache: true
+
+- name: Config docker proxy
+  block:
+    - name: Check that /etc/systemd/system/docker.service.d exists
+      stat:
+        path: "/etc/systemd/system/docker.service.d"
+      register: dir_stats
+
+    - name: Create /etc/systemd/system/docker.service.d if not exists
+      file:
+        path: "/etc/systemd/system/docker.service.d"
+        state: directory
+      when: not dir_stats.stat.exists
+
+    - name: Create proxy conf file under /etc/systemd/system/docker.service.d/
+      file:
+        path: "/etc/systemd/system/docker.service.d/http-proxy.conf"
+        state: touch
+
+    - name: Config docker proxy in http-proxy.conf
+      blockinfile:
+        dest: "/etc/systemd/system/docker.service.d/http-proxy.conf"
+        block: |
+          [Service]
+          Environment="HTTP_PROXY={{ idf.proxy_settings.http_proxy }}"
+          Environment="HTTPS_PROXY={{ idf.proxy_settings.https_proxy }}"
+          Environment="NO_PROXY={{ idf.proxy_settings.no_proxy }}"
+  when:
+    idf.proxy_settings is defined
+
+- 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/tasks/install-packages-Debian.yml b/playbooks/roles/configure-targethosts/tasks/install-packages-Debian.yml
index ab8cf63..326d2c0 100644
--- a/playbooks/roles/configure-targethosts/tasks/install-packages-Debian.yml
+++ b/playbooks/roles/configure-targethosts/tasks/install-packages-Debian.yml
@@ -17,29 +17,19 @@
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
 
+- name: Load distribution variables
+  include_vars: '{{ ansible_os_family }}.yml'
+
 - name: Install packages
   apt:
-    name: "{{ item }}"
+    name: "{{ packages }}"
     state: present
     update_cache: true
-  with_items:
-    - "apt-transport-https"
-    - "ca-certificates"
-    - "curl"
-    - "gnupg-agent"
-    - "software-properties-common"
-    - "chrony"
-    - "dbus"
-    - "lvm2"
-    - "nfs-kernel-server"
-    - "tzdata"
-    - "parted"
 
-# NOTE: raw install is required to support cloud images which do not have python installed
-# This is copied from kolla-ansible: ansible/roles/baremetal/tasks/pre-install.yml
-# DEBIAN_FRONTEND=noninteractive is added for uninterrupted installation of packages
-- name: Install python2.7
-  raw: "DEBIAN_FRONTEND=noninteractive apt-get install -y python2.7"
-  changed_when: true
+- name: Install docker
+  apt:
+    name: "{{ docker_packages }}"
+    state: present
+    update_cache: true
 
 # vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml b/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml
index 29a64b3..56ec1bb 100644
--- a/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml
+++ b/playbooks/roles/configure-targethosts/tasks/install-packages-RedHat.yml
@@ -31,5 +31,20 @@
     - "nfs-kernel-server"
     - "tzdata"
     - "parted"
+    - "inetutils-ping"
+
+- 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: true
+  changed_when: false
+
+- 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/main.yml b/playbooks/roles/configure-targethosts/tasks/main.yml
index 783f029..91e3c3e 100644
--- a/playbooks/roles/configure-targethosts/tasks/main.yml
+++ b/playbooks/roles/configure-targethosts/tasks/main.yml
@@ -18,8 +18,26 @@
 # ============LICENSE_END=========================================================
 
 - include: configure-network.yml
-- include: install-packages.yml
+  when: provisioner_type == "bifrost"
+
+- include: "configure-{{ execution_mode }}.yaml"
+
 - include: sync-time.yml
+  when: execution_mode == 'online-deployment'
+
+# NOTE (fdegir): in some cases, the provisioned nodes do not have tzdata
+# installed on them, resulting incorrect timezone setting due to missing
+# timezone file and broken /etc/localtime symlink
+- name: Delete /etc/localtime
+  file:
+    path: /etc/localtime
+    state: absent
+  ignore_errors: true
+
+- name: Set timezone to UTC
+  timezone:
+    name: UTC
+
 - include: create-swap.yml
 - include: prepare-nova-kvm.yml
 - include: prepare-cinder-{{ cinder_storage_driver }}-{{ cinder_storage_type }}.yml
diff --git a/playbooks/roles/configure-targethosts/vars/Debian.yml b/playbooks/roles/configure-targethosts/vars/Debian.yml
index fa38673..5fe2e74 100644
--- a/playbooks/roles/configure-targethosts/vars/Debian.yml
+++ b/playbooks/roles/configure-targethosts/vars/Debian.yml
@@ -22,4 +22,23 @@
 chrony_config_keyfile: /etc/chrony/chrony.keys
 chrony_config_logdir: /var/log/chrony
 
+packages:
+  - apt-transport-https
+  - ca-certificates
+  - curl
+  - gnupg-agent
+  - software-properties-common
+  - chrony
+  - dbus
+  - lvm2
+  - nfs-kernel-server
+  - tzdata
+  - parted
+  - inetutils-ping
+
+docker_packages:
+  - docker-ce={{ docker_ce_version }}
+  - docker-ce-cli={{ docker_ce_cli_version }}
+  - containerd.io={{ containerd_io_version }}
+
 # vim: set ts=2 sw=2 expandtab: