Add setup for kubectl and helm
the kubeconfig is copied from the cluster config directory to ~/.kube/config.
Also, the playbook runs kubectl and helm roles to install tools.
Change-Id: I29ee98f6502bbb7923b1ae6812dd642ca206dbce
Issue-ID: OOM-1778
Signed-off-by: Petr OspalĂ˝ <p.ospaly@partner.samsung.com>
Signed-off-by: Michal Zegan <m.zegan@samsung.com>
diff --git a/ansible/rke.yml b/ansible/rke.yml
index 81e964d..e0d6dcf 100644
--- a/ansible/rke.yml
+++ b/ansible/rke.yml
@@ -24,3 +24,5 @@
- role: rke
vars:
mode: deploy
+ - kubectl
+ - helm
diff --git a/ansible/roles/kubectl/defaults/main.yml b/ansible/roles/kubectl/defaults/main.yml
index 78c15c7..b922fb5 100644
--- a/ansible/roles/kubectl/defaults/main.yml
+++ b/ansible/roles/kubectl/defaults/main.yml
@@ -1,5 +1,2 @@
---
kubectl_bin_dir: /usr/local/bin
-kube_directory: ~/.kube
-# Defaulting to rancher setup
-kube_server: "https://{{ ansible_host }}:8080/r/projects/{{ k8s_env_id | mandatory }}/kubernetes:6443"
\ No newline at end of file
diff --git a/ansible/roles/kubectl/tasks/main.yml b/ansible/roles/kubectl/tasks/main.yml
index 9ecb5c4..7c77c3c 100644
--- a/ansible/roles/kubectl/tasks/main.yml
+++ b/ansible/roles/kubectl/tasks/main.yml
@@ -5,13 +5,3 @@
dest: "{{ kubectl_bin_dir }}/kubectl"
remote_src: true
mode: 0755
-
-- name: Ensure .kube directory exists
- file:
- path: "{{ kube_directory }}"
- state: directory
-
-- name: Create kube config
- template:
- src: kube_config.j2
- dest: "{{ kube_directory }}/config"
diff --git a/ansible/roles/rancher/defaults/main.yml b/ansible/roles/rancher/defaults/main.yml
index 6d354e6..e4e12d2 100644
--- a/ansible/roles/rancher/defaults/main.yml
+++ b/ansible/roles/rancher/defaults/main.yml
@@ -4,6 +4,8 @@
rancher_redeploy_k8s_env: true
rancher_cluster_health_state: healthy
rancher_cluster_health_check_retries: 30
+kube_directory: ~/.kube
+kube_server: "https://{{ ansible_host }}:8080/r/projects/{{ k8s_env_id | mandatory }}/kubernetes:6443"
rancher:
# The following variables can be set via the UI under advanced/settings.
# All of these affect tables in the cattle db and are uninteresting
diff --git a/ansible/roles/rancher/tasks/rancher_server.yml b/ansible/roles/rancher/tasks/rancher_server.yml
index a0893b0..f467ff3 100644
--- a/ansible/roles/rancher/tasks/rancher_server.yml
+++ b/ansible/roles/rancher/tasks/rancher_server.yml
@@ -93,3 +93,13 @@
data:
option: audit_log.purge.after.seconds
value: "{{ rancher.audit_log_purge_after_seconds }}"
+
+- name: Ensure .kube directory exists
+ file:
+ path: "{{ kube_directory }}"
+ state: directory
+
+- name: Create kube config
+ template:
+ src: kube_config.j2
+ dest: "{{ kube_directory }}/config"
diff --git a/ansible/roles/kubectl/templates/kube_config.j2 b/ansible/roles/rancher/templates/kube_config.j2
similarity index 100%
rename from ansible/roles/kubectl/templates/kube_config.j2
rename to ansible/roles/rancher/templates/kube_config.j2
diff --git a/ansible/roles/rke/defaults/main.yml b/ansible/roles/rke/defaults/main.yml
index 3e1c26a..cbf03b7 100644
--- a/ansible/roles/rke/defaults/main.yml
+++ b/ansible/roles/rke/defaults/main.yml
@@ -2,8 +2,10 @@
rke_binary: rke
rke_username: rke
rke_bin_dir: /usr/local/bin
+kube_config_dir: "{{ ansible_env.HOME }}/.kube"
cluster_config_dir: "{{ app_data_path }}/cluster"
rke:
+ # rke (rancher) images
etcd: rancher/coreos-etcd:v3.2.24-rancher1
alpine: rancher/rke-tools:v0.1.27
nginx_proxy: rancher/rke-tools:v0.1.27
diff --git a/ansible/roles/rke/tasks/rke_deploy.yml b/ansible/roles/rke/tasks/rke_deploy.yml
index 7b3e251..9983d08 100644
--- a/ansible/roles/rke/tasks/rke_deploy.yml
+++ b/ansible/roles/rke/tasks/rke_deploy.yml
@@ -3,3 +3,15 @@
command: "{{ rke_bin_dir }}/rke up --config cluster.yml"
args:
chdir: "{{ cluster_config_dir }}"
+
+- name: Ensure .kube directory is present
+ file:
+ path: "{{ kube_config_dir }}"
+ state: directory
+
+- name: Setup kubeconfig
+ copy:
+ src: "{{ cluster_config_dir }}/kube_config_cluster.yml"
+ dest: "{{ kube_config_dir }}/config"
+ remote_src: true
+ mode: 0755