-
-
Notifications
You must be signed in to change notification settings - Fork 316
/
Copy pathmain.yml
87 lines (78 loc) · 2.32 KB
/
main.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
---
- hosts: localhost
gather_facts: false
vars:
ansible_python_interpreter: '{{ ansible_playbook_python }}'
image_name: hello-go
pre_tasks:
- name: Check Minikube's status.
command: minikube status
register: minikube_status
changed_when: false
ignore_errors: true
- name: Start Minikube if it's not running.
command: minikube start
when: "not minikube_status.stdout or 'Running' not in minikube_status.stdout"
tasks:
# Build the hello-go Docker image inside Minikube's environment.
- name: Get existing image hash.
shell: |
eval $(minikube docker-env)
docker images -q {{ image_name }}
register: image_hash
changed_when: false
- name: Build image if it's not already built.
shell: |
eval $(minikube docker-env)
docker build -t {{ image_name }} ../hello-go
when: not image_hash.stdout
# Create Kubernetes resources to run Hello Go.
- name: Create a Deployment for Hello Go.
k8s:
state: present
definition:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-go
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: hello-go
template:
metadata:
labels:
app: hello-go
spec:
containers:
- name: hello-go
image: "{{ image_name }}"
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8180
- name: Create a Service for Hello Go.
k8s:
state: present
definition:
apiVersion: v1
kind: Service
metadata:
name: hello-go
namespace: default
spec:
type: LoadBalancer
ports:
- port: 8180
targetPort: 8180
selector:
app: hello-go
post_tasks:
- name: Expose Hello Go on the host via Minikube.
command: minikube service hello-go --url=true
changed_when: false
register: minikube_service
- name: Print Hello Go URL.
debug:
msg: "Hello Go URL: {{ minikube_service['stdout_lines'][0] }}"