summaryrefslogtreecommitdiffstats
path: root/tools/docker-compose-minikube/minikube/tasks/main.yml
blob: aa2c4c8c8da0a436f8b60a2d0258da9d5a086aa1 (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
---
- name: Create _sources directory
  file:
    path: "{{ sources_dest }}"
    state: 'directory'
    mode: '0700'

# Linux block
- block:
    - name: Download Minikube
      get_url:
        url: "{{ minikube_url_linux }}"
        dest: "{{ sources_dest }}/minikube"
        mode: 0755

    - name: Download Kubectl
      get_url:
        url: "{{ kubectl_url_linux }}"
        dest: "{{ sources_dest }}/kubectl"
        mode: 0755
  when:
    - ansible_architecture == "x86_64"
    - ansible_system == "Linux"

# MacOS block
- block:
    - name: Download Minikube
      get_url:
        url: "{{ minikube_url_macos }}"
        dest: "{{ sources_dest }}/minikube"
        mode: 0755

    - name: Download Kubectl
      get_url:
        url: "{{ kubectl_url_macos }}"
        dest: "{{ sources_dest }}/kubectl"
        mode: 0755
  when:
    - ansible_architecture == "x86_64"
    - ansible_system == "Darwin"

- name: Starting Minikube
  shell: "{{ sources_dest }}/minikube start --driver={{ driver }} --install-addons=true --addons=ingress"

- name: Create ServiceAccount and clusterRoleBinding
  k8s:
    apply: true
    definition: "{{ lookup('template', 'rbac.yml.j2') }}"

- name: Retrieve serviceAccount secret name
  k8s_info:
    kind: ServiceAccount
    namespace: '{{ minikube_service_account_namespace }}'
    name: '{{ minikube_service_account_name }}'
  register: service_account

- name: Register serviceAccount secret name
  set_fact:
    _service_account_secret_name: '{{ service_account["resources"][0]["secrets"][0]["name"] }}'
  when:
    - service_account["resources"][0]["secrets"] | length
    - '"name" in service_account["resources"][0]["secrets"][0]'

- name: Retrieve bearer_token from serviceAccount secret
  k8s_info:
    kind: Secret
    namespace: '{{ minikube_service_account_namespace }}'
    name: '{{ _service_account_secret_name }}'
  register: _service_account_secret

- name: Load Minikube Bearer Token
  set_fact:
    service_account_token: '{{ _service_account_secret["resources"][0]["data"]["token"] | b64decode }}'
  when:
    - _service_account_secret["resources"][0]["data"] | length

- name: Render minikube credential JSON template
  template:
    src: bootstrap_minikube.py.j2
    dest: "{{ sources_dest }}/bootstrap_minikube.py"
    mode: '0600'