diff --git a/roles/install-kubernetes/README.rst b/roles/install-kubernetes/README.rst new file mode 100644 index 000000000..ea0d962f8 --- /dev/null +++ b/roles/install-kubernetes/README.rst @@ -0,0 +1,8 @@ +An ansible role to install kubernetes. + +**Role Variables** + +.. zuul:rolevar:: install_kubernetes_with_cluster + :default: True + + If true, installs a Minikube cluster. diff --git a/roles/install-kubernetes/defaults/main.yaml b/roles/install-kubernetes/defaults/main.yaml new file mode 100644 index 000000000..19ff90d2d --- /dev/null +++ b/roles/install-kubernetes/defaults/main.yaml @@ -0,0 +1 @@ +install_kubernetes_with_cluster: True diff --git a/roles/install-kubernetes/tasks/main.yaml b/roles/install-kubernetes/tasks/main.yaml new file mode 100644 index 000000000..445f71c88 --- /dev/null +++ b/roles/install-kubernetes/tasks/main.yaml @@ -0,0 +1,21 @@ +- name: Install apt key + become: yes + apt_key: + url: "https://packages.cloud.google.com/apt/doc/apt-key.gpg" + state: present + +- name: Add kubernetes repo + become: yes + apt_repository: + repo: deb http://apt.kubernetes.io/ kubernetes-xenial main + state: present + +- name: Install kubernetes packages + become: yes + apt: + name: kubectl + update_cache: yes + +- name: Run cluster tasks + include_tasks: minikube.yaml + when: install_kubernetes_with_cluster diff --git a/roles/install-kubernetes/tasks/minikube.yaml b/roles/install-kubernetes/tasks/minikube.yaml new file mode 100644 index 000000000..d0c2f50c1 --- /dev/null +++ b/roles/install-kubernetes/tasks/minikube.yaml @@ -0,0 +1,48 @@ +- name: Check for Minikube install + stat: + path: /tmp/minikube + register: stat_result + +- name: Download Minikube + get_url: + url: https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 + dest: /tmp/minikube + mode: 0755 + when: stat_result.stat.exists == False + +- name: Run install-docker role + include_role: + name: install-docker + +- name: Create .kube directory + file: + path: "{{ ansible_user_dir }}/.kube" + state: directory + mode: 0755 + +- name: Create .kube/config file + file: + path: "{{ ansible_user_dir }}/.kube/config" + state: touch + mode: 0644 + +- name: Create .minikube directory + file: + path: "{{ ansible_user_dir }}/.minikube" + state: directory + mode: 0755 + +- name: Start Minikube + become: yes + command: /tmp/minikube --vm-driver=none start + environment: + MINIKUBE_WANTUPDATENOTIFICATION: false + MINIKUBE_WANTREPORTERRORPROMPT: false + MINIKUBE_WANTNONEDRIVERWARNING: false + MINIKUBE_WANTKUBECTLDOWNLOADMSG: false + CHANGE_MINIKUBE_NONE_USER: true + MINIKUBE_HOME: "{{ ansible_user_dir }}" + KUBECONFIG: "{{ ansible_user_dir }}/.kube/config" + +- name: Get cluster info + command: kubectl cluster-info