| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- ---
- - name: "Check if {{ minikube_profile_name }} already exists"
- ansible.builtin.command:
- argv:
- - minikube
- - profile
- - list
- - --light=true
- - --output=json
- register: profile_check_result
- changed_when: False
- ignore_errors: true
- - name: "Set minikube profile JSON Facts"
- set_fact:
- minikube_profiles_json: "{{ profile_check_result.stdout | from_json }}"
- - name: Set if no profiles exist
- set_fact:
- no_profiles: "{{ minikube_profiles_json.valid | length == 0 }}"
- - name: "Existing minikube profiles"
- debug:
- msg: "{{ minikube_profiles_json | json_query(profile_name_query) }}"
-
- - name: "Set profiles to be created"
- set_fact:
- minikube_profiles: "{{ minikube_profiles | combine( { item.key:{'create': ((not item.value.destroy) and ( item.key not in profile_names or no_profiles )) }}, recursive=True ) }}"
- loop: "{{ minikube_profiles | dict2items }}"
- loop_control:
- label: "{{ item.key }}"
- vars:
- profile_names: "{{ minikube_profiles_json | json_query(profile_name_query) }}"
- - name: "Debug::Minikube Clusters Config"
- debug:
- var: minikube_profiles
- - name: "Create Kubeconfig dir"
- file:
- state: directory
- path: "{{ kubeconfig_dir }}"
- - name: "Create minikube Kubernetes Cluster"
- command:
- argv:
- - "{{ minikube_binary }}"
- - -p
- - "{{ item.key }}"
- - start
- # TODO #2 load the start up parameters from CLI
- - "--memory={{ item.value.memory | default(minikube_default_memory) }}"
- - "--cpus={{ item.value.cpus | default(minikube_default_cpus) }}"
- - "--disk-size={{ item.value.disk_size | default(minikube_default_disk_size) }}"
- - "--delete-on-failure=true"
- - "--driver={{ minikube_driver }}"
- - "--insecure-registry=10.0.0.0/24"
- - --kubernetes-version={{ kubernetes_version | default(minikube_kubernetes_version) }}
- - "--service-cluster-ip-range={{ item.value.service_cluster_ip_range | default(minikube_service_cluster_ip_range) }}"
- register: minikube_start_result
- loop: "{{ minikube_profiles | dict2items }}"
- loop_control:
- label: "{{ item.key }}"
- environment:
- KUBECONFIG: "{{ kubeconfig_dir }}/{{ item.key }}.kubeconfig"
- when: (item.value.create | bool) and not ( item.value.destroy | bool )
- - name: "Fail when cluster not started"
- fail:
- msg: "Unable to start minikube"
- when: minikube_start_result.changed and item.rc != 0
- loop: "{{ minikube_start_result.results }}"
- loop_control:
- label: "{{ item.item.key }}"
- - name: "Check if local .kube directory exists"
- stat:
- path: "{{ kubeconfig_dir }}"
- register: kubeconfig_dir_result
- - debug:
- var: kubeconfig_dir_result
- - name: "Merge Kubconfig"
- set_fact:
- kubeconfig: "{{ lookup('fileglob', kubeconfig_dir +'/*.kubeconfig') | regex_replace(',',':') }}"
- when: kubeconfig_dir_result.stat.exists
- - name: "Merge and Flatten Kubeconfig"
- local_action:
- module: ansible.builtin.command
- argv:
- - kubectl
- - config
- - view
- - --flatten
- register: merged_kubeconfig
- environment:
- KUBECONFIG: "{{ kubeconfig }}"
- when: kubeconfig_dir_result.stat.exists
- - name: "Save work Kubeconfig"
- local_action:
- module: ansible.builtin.copy
- dest: "{{ kubeconfig_dir }}/config"
- content: "{{ merged_kubeconfig.stdout | from_yaml | to_nice_yaml(indent=2) }}"
- when: kubeconfig_dir_result.stat.exists
- - name: "Enabling addon"
- ansible.builtin.command:
- argv:
- - "{{ minikube_binary }}"
- - -p
- - "{{ item.0.key }}"
- - addons
- - enable
- - "{{ item.1 }}"
- loop: "{{ minikube_profiles | dict2items | subelements('value.addons',skip_missing=True)}}"
- register: addons_enable_result
- changed_when: False
- loop_control:
- label: "Enabling addon '{{ item.1}}' on '{{ item.0.key }}'"
- when: ( ( item.0.value.create | bool ) and not ( item.0.value.destroy | bool ) ) or force_enable_addon
- environment:
- KUBECONFIG: "{{ playbook_dir }}/.kube/{{ item.0.key }}.kubeconfig"
|