From c576e4d4864d739568b7fec76cff381b859e66f6 Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Thu, 7 Sep 2017 19:39:45 +0100
Subject: [PATCH] Add support for Ubuntu control hosts

This enables the user to use an Ubuntu machine to manage the cloud. The
remote cloud hosts must still run CentOS.
---
 ansible/roles/bootstrap/tasks/main.yml        |  8 ++--
 ansible/roles/bootstrap/vars/Debian.yml       |  5 +++
 ansible/roles/bootstrap/vars/RedHat.yml       |  5 +++
 ansible/roles/ip-allocation/tasks/main.yml    | 23 ++++++++---
 ansible/roles/ip-allocation/vars/Debian.yml   |  8 ++++
 ansible/roles/ip-allocation/vars/RedHat.yml   |  8 ++++
 ansible/roles/kolla-ansible/tasks/install.yml | 14 +++----
 ansible/roles/kolla-ansible/vars/Debian.yml   | 10 +++++
 ansible/roles/kolla-ansible/vars/RedHat.yml   | 10 +++++
 doc/source/installation.rst                   | 40 +++++++++++++++----
 10 files changed, 105 insertions(+), 26 deletions(-)
 create mode 100644 ansible/roles/bootstrap/vars/Debian.yml
 create mode 100644 ansible/roles/bootstrap/vars/RedHat.yml
 create mode 100644 ansible/roles/ip-allocation/vars/Debian.yml
 create mode 100644 ansible/roles/ip-allocation/vars/RedHat.yml
 create mode 100644 ansible/roles/kolla-ansible/vars/Debian.yml
 create mode 100644 ansible/roles/kolla-ansible/vars/RedHat.yml

diff --git a/ansible/roles/bootstrap/tasks/main.yml b/ansible/roles/bootstrap/tasks/main.yml
index 137420d9..6b8c67e0 100644
--- a/ansible/roles/bootstrap/tasks/main.yml
+++ b/ansible/roles/bootstrap/tasks/main.yml
@@ -1,12 +1,12 @@
 ---
+- include_vars: "{{ ansible_os_family }}.yml"
+
 - name: Ensure required packages are installed
-  yum:
+  package:
     name: "{{ item }}"
     state: installed
   become: True
-  with_items:
-    - git
-    - vim
+  with_items: "{{ bootstrap_package_dependencies }}"
 
 - name: Check whether an SSH key exists
   stat:
diff --git a/ansible/roles/bootstrap/vars/Debian.yml b/ansible/roles/bootstrap/vars/Debian.yml
new file mode 100644
index 00000000..dd037d12
--- /dev/null
+++ b/ansible/roles/bootstrap/vars/Debian.yml
@@ -0,0 +1,5 @@
+---
+# List of package dependencies to install.
+bootstrap_package_dependencies:
+  - git
+  - vim
diff --git a/ansible/roles/bootstrap/vars/RedHat.yml b/ansible/roles/bootstrap/vars/RedHat.yml
new file mode 100644
index 00000000..dd037d12
--- /dev/null
+++ b/ansible/roles/bootstrap/vars/RedHat.yml
@@ -0,0 +1,5 @@
+---
+# List of package dependencies to install.
+bootstrap_package_dependencies:
+  - git
+  - vim
diff --git a/ansible/roles/ip-allocation/tasks/main.yml b/ansible/roles/ip-allocation/tasks/main.yml
index 7fc9ccab..2707f600 100644
--- a/ansible/roles/ip-allocation/tasks/main.yml
+++ b/ansible/roles/ip-allocation/tasks/main.yml
@@ -1,16 +1,29 @@
 ---
-# Note: Currently we install these using Yum to the system packages rather than
+# Facts may not be available for the control host, so read the OS release
+# manually.
+- name: Check the OS release
+  local_action:
+    module: shell . /etc/os-release && echo $ID
+  changed_when: False
+  register: ip_allocation_os_release
+
+- include_vars: "RedHat.yml"
+  when: ip_allocation_os_release.stdout in ['centos', 'fedora', 'rhel']
+
+- include_vars: "Debian.yml"
+  when: ip_allocation_os_release.stdout in ['debian', 'ubuntu']
+
+# Note: Currently we install these using the system package manager rather than
 # pip to a virtualenv. This is because Yum is required elsewhere and cannot
 # easily be installed in a virtualenv.
 - name: Ensure package dependencies are installed
   local_action:
-    module: yum
+    module: package
     name: "{{ item }}"
     state: installed
+    use: "{{ ip_allocation_package_manager }}"
   become: True
-  with_items:
-    - python-netaddr
-    - PyYAML
+  with_items: "{{ ip_allocation_package_dependencies }}"
   run_once: True
 
 - name: Ensure IP addresses are allocated
diff --git a/ansible/roles/ip-allocation/vars/Debian.yml b/ansible/roles/ip-allocation/vars/Debian.yml
new file mode 100644
index 00000000..00caec72
--- /dev/null
+++ b/ansible/roles/ip-allocation/vars/Debian.yml
@@ -0,0 +1,8 @@
+---
+# Package manager to use.
+ip_allocation_package_manager: apt
+
+# List of packages to install.
+ip_allocation_package_dependencies:
+  - python-netaddr
+  - python-yaml
diff --git a/ansible/roles/ip-allocation/vars/RedHat.yml b/ansible/roles/ip-allocation/vars/RedHat.yml
new file mode 100644
index 00000000..0c9c9042
--- /dev/null
+++ b/ansible/roles/ip-allocation/vars/RedHat.yml
@@ -0,0 +1,8 @@
+---
+# Package manager to use.
+ip_allocation_package_manager: yum
+
+# List of packages to install.
+ip_allocation_packages:
+  - python-netaddr
+  - PyYAML
diff --git a/ansible/roles/kolla-ansible/tasks/install.yml b/ansible/roles/kolla-ansible/tasks/install.yml
index 9010ce21..6880f76f 100644
--- a/ansible/roles/kolla-ansible/tasks/install.yml
+++ b/ansible/roles/kolla-ansible/tasks/install.yml
@@ -1,23 +1,19 @@
 ---
+- include_vars: "{{ ansible_os_family }}.yml"
+
 - name: Ensure EPEL repo is installed
   yum:
     name: epel-release
     state: installed
   become: True
+  when: ansible_os_family == 'RedHat'
 
 - name: Ensure required packages are installed
-  yum:
+  package:
     name: "{{ item }}"
     state: installed
   become: True
-  with_items:
-    - gcc
-    - libffi-devel
-    - openssl-devel
-    - patch
-    - python-devel
-    - python-pip
-    - python-virtualenv
+  with_items: "{{ kolla_ansible_package_dependencies }}"
 
 - name: Ensure source code checkout path exists
   file:
diff --git a/ansible/roles/kolla-ansible/vars/Debian.yml b/ansible/roles/kolla-ansible/vars/Debian.yml
new file mode 100644
index 00000000..9f9aaa97
--- /dev/null
+++ b/ansible/roles/kolla-ansible/vars/Debian.yml
@@ -0,0 +1,10 @@
+---
+# List of packages to install.
+kolla_ansible_package_dependencies:
+  - gcc
+  - libffi-dev
+  - libssl-dev
+  - patch
+  - python-dev
+  - python-pip
+  - python-virtualenv
diff --git a/ansible/roles/kolla-ansible/vars/RedHat.yml b/ansible/roles/kolla-ansible/vars/RedHat.yml
new file mode 100644
index 00000000..6b84963e
--- /dev/null
+++ b/ansible/roles/kolla-ansible/vars/RedHat.yml
@@ -0,0 +1,10 @@
+---
+# List of packages to install.
+kolla_ansible_package_dependencies:
+  - gcc
+  - libffi-devel
+  - openssl-devel
+  - patch
+  - python-devel
+  - python-pip
+  - python-virtualenv
diff --git a/doc/source/installation.rst b/doc/source/installation.rst
index 62272d72..2210f637 100644
--- a/doc/source/installation.rst
+++ b/doc/source/installation.rst
@@ -5,26 +5,50 @@ Installation
 Prerequisites
 =============
 
-Currently Kayobe supports the following Operating Systems:
+Currently Kayobe supports the following Operating Systems on the control host:
 
 - CentOS 7.3
+- Ubuntu 16.04
 
 To avoid conflicts with python packages installed by the system package manager
 it is recommended to install Kayobe in a virtualenv. Ensure that the
-``virtualenv`` python module is available on the control host. For example, on
-CentOS::
+``virtualenv`` python module is available on the control host.
 
-    $ yum install -y python-virtualenv
+.. code-block:: console
+   :caption: CentOS
+
+   $ yum install -y python-virtualenv
+
+.. code-block:: console
+   :caption: Ubuntu
+
+   $ apt install -y python-virtualenv
 
 It is necessary to install the GCC compiler chain in order to build the
-extensions of some of kayobe's python dependencies. On CentOS::
+extensions of some of kayobe's python dependencies.
+
+.. code-block:: console
+   :caption: CentOS
+
+   $ yum install -y gcc
 
-    $ yum install -y gcc
+.. code-block:: console
+   :caption: Ubuntu
+
+   $ apt install -y gcc
 
 Finally, for cloning and working with the kayobe source code repository, Git is
-required. On CentOS::
+required.
+
+.. code-block:: console
+   :caption: CentOS
+
+   $ yum install -y git
+
+.. code-block:: console
+   :caption: Ubuntu
 
-    $ yum install -y git
+   $ apt install -y git
 
 Installation
 ============
-- 
GitLab