4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 - name: create directory
18 name: "{{ config.path | dirname }}"
21 owner: "{{ config.owner | default('root') }}"
22 group: "{{ config.group | default('root') }}"
24 - name: create kubeconfig
25 command: "/usr/bin/kubectl config {{ cmd }} --kubeconfig={{ config.path }}"
27 - "set-cluster kubernetes --certificate-authority=/etc/openssl/ca.pem --embed-certs=true --server=https://{{ config.apiserver }}:{{ config.apiserver_port }}"
28 - "set-context default --cluster=kubernetes --user={{ config.user }}"
29 - "use-context default"
33 - name: set user auth with token
34 command: "/usr/bin/kubectl config set-credentials {{ config.user }} --token={{ config.token }} --kubeconfig={{ config.path }}"
35 when: config.token is defined and config.token
37 - name: set user auth with certs
38 command: "/usr/bin/kubectl config set-credentials {{ config.user }} --client-certificate={{ config.cert }} --client-key={{ config.key }} --embed-certs=true --kubeconfig={{ config.path }}"
39 when: not (config.token is defined and config.token)
41 - name: changing permissions of kubeconfig
43 path: "{{ config.path }}"
44 mode: "{{ config.restricted | default(true) | ternary('0640', '0644') }}"
45 owner: "{{ config.owner | default('root') }}"
46 group: "{{ config.group | default('root') }}"
48 - name: allowing users to access kubeconfig
50 name: "{{ config.path }}"
55 with_items: "{{ config.add_users | default([]) }}"
59 - name: adding read permission to kubeconfig dir
61 name: "{{ config.path | dirname }}"
66 with_items: "{{ config.add_users | default([]) }}"