Added seed code for caas-kubernetes.
[ta/caas-kubernetes.git] / ansible / roles / kube_secret_key_creation / tasks / main.yml
diff --git a/ansible/roles/kube_secret_key_creation/tasks/main.yml b/ansible/roles/kube_secret_key_creation/tasks/main.yml
new file mode 100644 (file)
index 0000000..65ad5ec
--- /dev/null
@@ -0,0 +1,41 @@
+---
+# Copyright 2019 Nokia
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+- name: check instance secret
+  stat:
+    path: "{{ caas.cert_path }}/{{ caas._secrets_conf }}"
+  register: secrets_conf
+
+- name: Generate key
+  command: "bash -c \"head -c 32 /dev/urandom | base64 -i - \""
+  register: kube_secret_enc_key
+  no_log: True
+  when: not secrets_conf.stat.exists
+
+- name: template secrets.conf
+  template:
+    src: "secrets.conf"
+    dest: "{{ caas.cert_path }}/{{ caas._secrets_conf }}"
+    mode: 0000
+  when: not secrets_conf.stat.exists
+
+- name: adding default acl read to {{ users.admin_user_name }} to {{ caas.cert_path }}/{{ caas._secrets_conf }}
+  acl:
+    name:  "{{ caas.cert_path }}/{{ caas._secrets_conf }}"
+    entity: "{{ users.admin_user_name }}"
+    etype: user
+    permissions: rx
+    state: present
+  when: not secrets_conf.stat.exists