From dbb6f4934eaf1a177db7fc182023a8ae81ee5267 Mon Sep 17 00:00:00 2001 From: Smaine Kahlouch Date: Wed, 30 Dec 2015 22:15:18 +0100 Subject: [PATCH] common role in order to support other linux distribs --- cluster.yml | 6 +- roles/common/defaults/main.yml | 13 +- roles/common/files/bootstrap.sh | 29 + roles/common/files/get-pip.py | 17474 ++++++++++++++++ roles/common/files/runner | 3 + roles/common/tasks/calico.yml | 27 - .../flannel.yml => common/tasks/download.yml} | 44 + roles/common/tasks/flannel.yml | 39 - roles/common/tasks/kubernetes.yml | 17 - roles/common/tasks/main.yml | 24 +- roles/common/tasks/python-bootstrap.yml | 41 + roles/download/defaults/main.yml | 16 - roles/download/tasks/calico.yml | 27 - roles/download/tasks/kubernetes.yml | 17 - roles/download/tasks/main.yml | 4 - 15 files changed, 17619 insertions(+), 162 deletions(-) create mode 100644 roles/common/files/bootstrap.sh create mode 100644 roles/common/files/get-pip.py create mode 100644 roles/common/files/runner delete mode 100644 roles/common/tasks/calico.yml rename roles/{download/tasks/flannel.yml => common/tasks/download.yml} (52%) delete mode 100644 roles/common/tasks/flannel.yml delete mode 100644 roles/common/tasks/kubernetes.yml create mode 100644 roles/common/tasks/python-bootstrap.yml delete mode 100644 roles/download/defaults/main.yml delete mode 100644 roles/download/tasks/calico.yml delete mode 100644 roles/download/tasks/kubernetes.yml delete mode 100644 roles/download/tasks/main.yml diff --git a/cluster.yml b/cluster.yml index 5d3a5cdb8..11fd08f44 100644 --- a/cluster.yml +++ b/cluster.yml @@ -1,11 +1,7 @@ --- -- hosts: downloader - sudo: no - roles: - - { role: download, tags: download } - - hosts: k8s-cluster roles: + - { role: common, tags: common } - { role: docker, tags: docker } - { role: kubernetes/node, tags: node } - { role: etcd, tags: etcd } diff --git a/roles/common/defaults/main.yml b/roles/common/defaults/main.yml index 339c72ac0..790a52b04 100644 --- a/roles/common/defaults/main.yml +++ b/roles/common/defaults/main.yml @@ -5,16 +5,19 @@ flannel_version: 0.5.5 kube_version: v1.1.3 kubectl_checksum: "01b9bea18061a27b1cf30e34fd8ab45cfc096c9a9d57d0ed21072abb40dd3d1d" kubelet_checksum: "62191c66f2d670dd52ddf1d88ef81048977abf1ffaa95ee6333299447eb6a482" +kube_download_url: "https://storage.googleapis.com/kubernetes-release/release/{{ kube_version }}/bin/linux/amd64" calico_version: v0.13.0 calico_plugin_version: v0.7.0 -etcd_download_url: "https://github.com/coreos/etcd/releases/download" flannel_download_url: "https://github.com/coreos/flannel/releases/download" -kube_download_url: "https://storage.googleapis.com/kubernetes-release/release/{{ kube_version }}/bin/linux/amd64" calico_download_url: "https://github.com/Metaswitch/calico-docker/releases/download" calico_plugin_download_url: "https://github.com/projectcalico/calico-kubernetes/releases/download/{{calico_plugin_version}}/calico_kubernetes" -ansible_python_interpreter: PATH="{{ ansible_user_dir }}"/bin:$PATH python -pip_python_modules: - - httplib2 +req_debian_pkg: + - python-httplib2 + - python-apt + - python-pip + +pypy_version: 2.4.0 +python_pypy_url: "https://bitbucket.org/pypy/pypy/downloads/pypy-{{ pypy_version }}.tar.bz2" diff --git a/roles/common/files/bootstrap.sh b/roles/common/files/bootstrap.sh new file mode 100644 index 000000000..2b04a51a3 --- /dev/null +++ b/roles/common/files/bootstrap.sh @@ -0,0 +1,29 @@ +#/bin/bash +set -e + +BINDIR="/usr/local/bin" + +cd $BINDIR + +if [[ -e $BINDIR/.bootstrapped ]]; then + exit 0 +fi + +PYPY_VERSION=2.4.0 + +wget -O - https://bitbucket.org/pypy/pypy/downloads/pypy-$PYPY_VERSION-linux64.tar.bz2 |tar -xjf - +mv -n pypy-$PYPY_VERSION-linux64 pypy + +## library fixup +mkdir -p pypy/lib +ln -snf /lib64/libncurses.so.5.9 $BINDIR/pypy/lib/libtinfo.so.5 + +cat > $BINDIR/python < + if $(pgrep systemd > /dev/null); then + echo systemd; + else echo sysvinit; + fi + always_run: True + register: init_system_output -- name: Install httplib2 python module - pip: - executable: "{{ ansible_user_dir }}/bin/pip" +- set_fact: + init_system: "{{ init_system_output.stdout }}" + +- name: Install debian packages requirements + apt: name: "{{ item }}" - with_items: pip_python_modules + state: latest + when: ansible_os_family == "Debian" + with_items: req_debian_pkg + +- include: python-bootstrap.yml + when: ansible_os_family not in [ "Debian", "RedHat" ] diff --git a/roles/common/tasks/python-bootstrap.yml b/roles/common/tasks/python-bootstrap.yml new file mode 100644 index 000000000..409944317 --- /dev/null +++ b/roles/common/tasks/python-bootstrap.yml @@ -0,0 +1,41 @@ +--- +- name: Python | Check if bootstrap is needed + raw: stat {{ bin_dir}}/.bootstrapped + register: need_bootstrap + ignore_errors: True + +- name: Python | Run bootstrap.sh + script: bootstrap.sh + when: need_bootstrap | failed + +- set_fact: + ansible_python_interpreter: "{{ bin_dir }}/python" + +- name: Python | Check if we need to install pip + shell: "{{ansible_python_interpreter}} -m pip --version" + register: need_pip + ignore_errors: True + changed_when: false + when: need_bootstrap | failed + +- name: Python | Copy get-pip.py + copy: src=get-pip.py dest=~/get-pip.py + when: need_pip | failed + +- name: Python | Install pip + shell: "{{ansible_python_interpreter}} ~/get-pip.py" + when: need_pip | failed + +- name: Python | Remove get-pip.py + file: path=~/get-pip.py state=absent + when: need_pip | failed + +- name: Python | Install pip launcher + copy: src=runner dest={{ bin_dir }}/pip mode=0755 + when: need_pip | failed + +- name: Install required python modules + pip: + name: "{{ item }}" + with_items: pip_python_modules + diff --git a/roles/download/defaults/main.yml b/roles/download/defaults/main.yml deleted file mode 100644 index 0a2b3a177..000000000 --- a/roles/download/defaults/main.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -etcd_version: v2.2.2 -flannel_version: 0.5.5 - -kube_version: v1.1.3 -kubectl_checksum: "01b9bea18061a27b1cf30e34fd8ab45cfc096c9a9d57d0ed21072abb40dd3d1d" -kubelet_checksum: "62191c66f2d670dd52ddf1d88ef81048977abf1ffaa95ee6333299447eb6a482" - -calico_version: v0.13.0 -calico_plugin_version: v0.7.0 - -etcd_download_url: "https://github.com/coreos/etcd/releases/download" -flannel_download_url: "https://github.com/coreos/flannel/releases/download" -kube_download_url: "https://storage.googleapis.com/kubernetes-release/release/{{ kube_version }}/bin/linux/amd64" -calico_download_url: "https://github.com/Metaswitch/calico-docker/releases/download" -calico_plugin_download_url: "https://github.com/projectcalico/calico-kubernetes/releases/download/{{calico_plugin_version}}/calico_kubernetes" diff --git a/roles/download/tasks/calico.yml b/roles/download/tasks/calico.yml deleted file mode 100644 index 9fa82cac1..000000000 --- a/roles/download/tasks/calico.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -- name: Create calico release directory - local_action: file - path={{ local_release_dir }}/calico/bin - recurse=yes - state=directory - delegate_to: "{{ groups['kube-master'][0] }}" - -- name: Check if calicoctl has been downloaded - local_action: stat - path={{ local_release_dir }}/calico/bin/calicoctl - register: c_tar - delegate_to: "{{ groups['kube-master'][0] }}" - -# issues with get_url module and redirects, to be tested again in the near future -- name: Download calico - local_action: shell - curl -o {{ local_release_dir }}/calico/bin/calicoctl -Ls {{ calico_download_url }}/{{ calico_version }}/calicoctl - when: not c_tar.stat.exists - register: dl_calico - delegate_to: "{{ groups['kube-master'][0] }}" - - -- name: Download calico-kubernetes-plugin - local_action: get_url - url="{{calico_plugin_download_url}}" - dest="{{ local_release_dir }}/calico/bin/calico" diff --git a/roles/download/tasks/kubernetes.yml b/roles/download/tasks/kubernetes.yml deleted file mode 100644 index 0985a17d3..000000000 --- a/roles/download/tasks/kubernetes.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- name: Create kubernetes binary directory - local_action: file - path="{{ local_release_dir }}/kubernetes/bin" - state=directory - recurse=yes - -- name: Download kubelet and kubectl - local_action: get_url - url="{{ kube_download_url }}/{{ item.name }}" - dest="{{ local_release_dir }}/kubernetes/bin" - sha256sum="{{ item.checksum }}" - with_items: - - name: kubelet - checksum: "{{ kubelet_checksum }}" - - name: kubectl - checksum: "{{ kubectl_checksum }}" diff --git a/roles/download/tasks/main.yml b/roles/download/tasks/main.yml deleted file mode 100644 index ded856ba0..000000000 --- a/roles/download/tasks/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- include: kubernetes.yml -- include: calico.yml -- include: flannel.yml