Added seed code for caas-kubernetes.
[ta/caas-kubernetes.git] / ansible / roles / kube_token_creation / tasks / main.yml
1 ---
2 # Copyright 2019 Nokia
3 #
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
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 - name: create directory for kube token
17   file:
18     path: "{{ caas.cert_path }}"
19     state: directory
20     recurse: yes
21
22 - name: Check token
23   stat:
24     path: "{{ caas.cert_path }}/{{ caas.token_filename }}"
25   register: token_file
26
27 - name: Generate token
28   shell: "head -c 16 /dev/urandom | od -An -t x | tr -d ' '"
29   register: kube_token_output
30   no_log: true
31   when: not token_file.stat.exists
32
33 - name: Set token fact
34   set_fact:
35     kube_token: "{{ kube_token_output.stdout }}"
36   no_log: true
37   when: not token_file.stat.exists
38
39 - name: Save token
40   copy:
41     content: "{{ kube_token }}"
42     dest: "{{ caas.cert_path }}/{{ caas.token_filename }}"
43   when: not token_file.stat.exists
44
45 - name: Set permissions on token
46   acl:
47     name:  "{{ caas.cert_path }}/{{ caas.token_filename }}"
48     entity: "{{ item }}"
49     etype: user
50     permissions: r
51     state: present
52   when: not token_file.stat.exists
53   with_items:
54     - "{{ users.admin_user_name }}"
55     - "kube"
56
57 - name: Generate tokens.csv
58   template:
59     src: "tokens.csv"
60     dest: "{{ caas.cert_path }}/{{ caas.tokenscsv_filename }}"
61     mode: 0000
62   when: not token_file.stat.exists
63
64 - name: Set permissions on tokens.csv
65   acl:
66     name:  "{{ caas.cert_path }}/{{ caas.tokenscsv_filename }}"
67     entity: "{{ item }}"
68     etype: user
69     permissions: r
70     state: present
71   when: not token_file.stat.exists
72   with_items:
73     - "{{ users.admin_user_name }}"
74     - "kube"