aboutsummaryrefslogtreecommitdiffstats
path: root/ansible/roles/ansible-vvp-bootstrap/tasks/tls.yml
blob: e0346cf599caf6902d070984e28b50398495ea90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# -*- encoding: utf-8 -*-
# ============LICENSE_START=======================================================
# org.onap.vvp/engagementmgr
# ===================================================================
# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
# ===================================================================
#
# Unless otherwise specified, all software contained herein is licensed
# under the Apache License, Version 2.0 (the “License”);
# you may not use this software 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.
#
#
#
# Unless otherwise specified, all documentation contained herein is licensed
# under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
# you may not use this documentation except in compliance with the License.
# You may obtain a copy of the License at
#
#             https://creativecommons.org/licenses/by/4.0/
#
# Unless required by applicable law or agreed to in writing, documentation
# 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.
#
# ============LICENSE_END============================================
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
- name: create TLS dir
  file:
    state: directory
    path: "{{files_dir}}/tls"
    mode: 0755
  tags:
  - bootstrap
  - tls

- name: create TLS dir
  file:
    state: directory
    path: "{{assets_dir}}/tls"
    mode: 0755
  tags:
  - bootstrap
  - tls

- stat: path="{{files_dir}}/tls/ca-key.pem"
  register: ca_key

- name: create root CA
  shell: openssl genrsa -out {{files_dir}}/tls/ca-key.pem 2048
  when: not ca_key.stat.exists

- stat: path="{{files_dir}}/tls/ca.pem"
  register: ca

- name: create self signed cert
  shell: openssl req -x509 -new -nodes -key {{files_dir}}/tls/ca-key.pem -days 10000 -out {{files_dir}}/tls/ca.pem -subj "/CN=kube-ca"
  when: not ca.stat.exists

- name: Generate Config File
  template:
    src: openssl.config.j2
    dest: "{{files_dir}}/tls/{{item}}-openssl.config"
  with_items:
  - admin
  - apiserver
  - worker

- stat: path={{files_dir}}/tls/{{item}}-key.pem
  register: keyfiles
  with_items:
  - admin
  - apiserver
  - worker

- name: create keyfile
  shell: openssl genrsa -out {{files_dir}}/tls/{{item.item}}-key.pem 2048
  with_items: "{{keyfiles.results}}"
  when: not item.stat.exists

- stat: path={{files_dir}}/tls/{{item}}.csr
  register: csr_files
  with_items:
  - admin
  - apiserver
  - worker

- name: Create csr
  shell: openssl req -new -key {{files_dir}}/tls/{{item.item}}-key.pem -out {{files_dir}}/tls/{{item.item}}.csr -subj "/CN=kube-{{item.item}}" -config {{files_dir}}/tls/{{item.item}}-openssl.config
  with_items: "{{csr_files.results}}"
  when: not item.stat.exists

- stat: path={{files_dir}}/tls/{{item}}.pem
  register: pem_files
  with_items:
  - admin
  - apiserver
  - worker

- name: Create pemfile
  shell: openssl x509 -req -in {{files_dir}}/tls/{{item.item}}.csr -CA {{files_dir}}/tls/ca.pem -CAkey {{files_dir}}/tls/ca-key.pem -CAcreateserial -out {{files_dir}}/tls/{{item.item}}.pem -days 365 -extensions v3_req -extfile {{files_dir}}/tls/{{item.item}}-openssl.config
  with_items: "{{pem_files.results}}"
  when: not item.stat.exists

- name: Copy tls related files to assets
  copy:
    src: "{{files_dir}}/{{item}}"
    dest: "{{assets_dir}}/{{item}}"
    remote_src: yes
    backup: yes
  with_items:
    - tls/apiserver-key.pem
    - tls/apiserver.pem
    - tls/ca.pem
    - tls/worker-key.pem
    - tls/worker.pem

- name: Encode Admin Cert
  shell: base64 -w 0 {{files_dir}}/tls/admin.pem
  register: ADMIN_CERT_BASE64

- name: Encode Admin Key
  shell: base64 -w 0 {{files_dir}}/tls/admin-key.pem
  register: ADMIN_KEY_BASE64

- name: Encode CA Cert
  shell: base64 -w 0 {{files_dir}}/tls/ca.pem
  register: CA_CERT_BASE64

- name: Render kubeconfig
  template:
    src: kubeconfig.j2
    dest: "{{files_dir}}/kubeconfig"

- name: Fetch the new kubeconfig
  fetch:
    src: "{{files_dir}}/kubeconfig"
    dest: "{{inventory_dir}}/../k8/"
    flat: yes