summaryrefslogtreecommitdiffstats
path: root/ansible/roles/kubectl
diff options
context:
space:
mode:
authorSamuli Silvius <s.silvius@partner.samsung.com>2019-03-17 18:06:33 +0200
committerSamuli Silvius <s.silvius@partner.samsung.com>2019-03-20 18:51:16 +0200
commitc580efee7cf133d479fdc4b736ebfeab09d2f246 (patch)
tree3d4a5746768b58bd05e58397411e4d8921d989a1 /ansible/roles/kubectl
parentdbc6a7202dc89264a2857e12c625fb2328584a1e (diff)
Improve rancher role testability
Move functionality from playbook to rancher role. Introduce defaults for holding default values in rancher role. Other small changes noticed while testing rancher role with molecule. Issue-ID: OOM-1729 Change-Id: I83befa9f0964c67e209d3def76bafd2a61c1ef33 Signed-off-by: Samuli Silvius <s.silvius@partner.samsung.com>
Diffstat (limited to 'ansible/roles/kubectl')
-rw-r--r--ansible/roles/kubectl/defaults/main.yml5
-rw-r--r--ansible/roles/kubectl/tasks/main.yml10
-rw-r--r--ansible/roles/kubectl/templates/kube_config.j219
3 files changed, 34 insertions, 0 deletions
diff --git a/ansible/roles/kubectl/defaults/main.yml b/ansible/roles/kubectl/defaults/main.yml
new file mode 100644
index 00000000..78c15c75
--- /dev/null
+++ b/ansible/roles/kubectl/defaults/main.yml
@@ -0,0 +1,5 @@
+---
+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 7c77c3c5..9ecb5c44 100644
--- a/ansible/roles/kubectl/tasks/main.yml
+++ b/ansible/roles/kubectl/tasks/main.yml
@@ -5,3 +5,13 @@
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/kubectl/templates/kube_config.j2 b/ansible/roles/kubectl/templates/kube_config.j2
new file mode 100644
index 00000000..586c59d4
--- /dev/null
+++ b/ansible/roles/kubectl/templates/kube_config.j2
@@ -0,0 +1,19 @@
+apiVersion: v1
+kind: Config
+clusters:
+- cluster:
+ api-version: v1
+ insecure-skip-tls-verify: true
+ server: "{{ kube_server }}"
+ name: "{{ app_name }}"
+contexts:
+- context:
+ cluster: "{{ app_name }}"
+ user: "{{ app_name }}"
+ name: "{{ app_name }}"
+current-context: "{{ app_name }}"
+users:
+- name: "{{ app_name }}"
+ user:
+ token: "{{ (['Basic', [key_public, key_private] | join(':') | b64encode] | join(' ')) | b64encode }}"
+