forked from MT2017055/Ansible-tower-examples
-
Notifications
You must be signed in to change notification settings - Fork 2
/
kube.yml
118 lines (118 loc) · 3.52 KB
/
kube.yml
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
- hosts: localhost
vars:
zip_path: /tmp/kubeConfig-burms2dd0gn5n25d9dt0.zip
kube_config_path: /tmp/kubeConfig-burms2dd0gn5n25d9dt0
IC_IAM_TOKEN: "{{ lookup('env','IC_IAM_TOKEN') }}"
IC_IAM_REFRESH_TOKEN: "{{ lookup('env','IC_IAM_REFRESH_TOKEN') }}"
tasks:
- name: Download kubeconfig
get_url:
url: https://containers.cloud.ibm.com/global/v1/clusters/burms2dd0gn5n25d9dt0/config
dest: "{{ zip_path }}"
headers:
Authorization: "{{ lookup('env','IC_IAM_TOKEN') }}"
X-Auth-Refresh-Token: "{{ lookup('env','IC_IAM_REFRESH_TOKEN') }}"
# headers:
# "Authorization": '"{{ IC_IAM_TOKEN }}"'
# X-Auth-Refresh-Token: "{{ IC_IAM_REFRESH_TOKEN }}"
force: yes
- name: Delete earlier instances of kube config
file:
path: "{{ kube_config_path }}"
state: absent
- name: ansible create directory for unzip kubeconfig
file:
path: "{{ kube_config_path }}"
state: directory
- name: Unzip kube config
shell:
cmd: /usr/bin/unzip "{{ zip_path }}" -d "{{ kube_config_path }}"
- name: Read config.yaml into kube_config var
shell:
cmd: find "{{kube_config_path}}" -name "*.yml"
register: kube_config
- name: Display the kubeconfig file path
debug:
var: kube_config.stdout
- name: Create Web Application
k8s:
kubeconfig: "{{ kube_config.stdout }}"
api_version: v1
namespace: default
definition:
kind: Deployment
metadata:
name: knote
spec:
replicas: 1
selector:
matchLabels:
app: knote
template:
metadata:
labels:
app: knote
spec:
containers:
- name: app
image: rvsingh011/hackathon-starter_web
ports:
- containerPort: 8080
env:
- name: MONGODB_URI
value: mongodb://mongo:27017/test
imagePullPolicy: Always
- name: Create web service
k8s:
kubeconfig: "{{ kube_config.stdout }}"
api_version: v1
namespace: default
definition:
kind: Service
metadata:
name: knote
spec:
selector:
app: knote
ports:
- port: 80
targetPort: 8080
type: LoadBalancer
- name: Create Database service
k8s:
kubeconfig: "{{ kube_config.stdout }}"
api_version: v1
namespace: default
definition:
kind: Deployment
metadata:
name: mongo
spec:
selector:
matchLabels:
app: mongo
template:
metadata:
labels:
app: mongo
spec:
containers:
- name: mongo
image: mongo
ports:
- containerPort: 27017
- name: Mongo Service
k8s:
kubeconfig: "{{ kube_config.stdout }}"
api_version: v1
namespace: default
definition:
kind: Service
metadata:
name: mongo
spec:
selector:
app: mongo
ports:
- port: 27017
targetPort: 27017