Page MenuHomePhorge

playbook.yaml
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

playbook.yaml

---
- name: Check local requirements
hosts: localhost
gather_facts: false
any_errors_fatal: true
tasks:
- name: Check if kubectl is available
ansible.builtin.raw: which kubectl
check_mode: false
changed_when: false
failed_when: which_res.rc > 1
register: which_res
- name: Check if kolabctl is available
ansible.builtin.shell:
cmd: env PATH="./:$PATH" which kolabctl
chdir: "{{ inventory_dir }}"
check_mode: false
changed_when: false
failed_when: which_res.rc > 1
register: which_res
- ansible.builtin.set_fact:
kolabctl_path: "{{ which_res.stdout }}"
- name: Assert that we found kolabctl
ansible.builtin.assert:
that: "kolabctl_path"
- name: Configure KVM
hosts: infrastructure_nodes:worker_nodes
gather_facts: false
any_errors_fatal: true
roles:
- kvm
# We have to run it with serial=1, otherwise it's not executed per host
- name: Update hosts
hosts: infrastructure_nodes:worker_nodes
gather_facts: false
serial: 1
tasks:
- name: Add a host alias so we can connect to the discovered vm ip
ansible.builtin.add_host:
hostname: '{{ inventory_hostname }}'
ansible_host: '{{ vm_ip.stdout }}'
- name: Configure kolab-node
hosts: infrastructure_nodes:worker_nodes
gather_facts: false
any_errors_fatal: true
roles:
- kolab-single-node
- name: Fetch kubeconfig.yaml
hosts: infrastructure_nodes[0]
gather_facts: false
tasks:
- fetch:
flat: true
src: /etc/rancher/k3s/k3s.yaml
dest: "{{ resources_dir }}/kubeconfig.yaml"
- name: Deploy kolab
hosts: localhost
gather_facts: false
tasks:
- ansible.builtin.set_fact:
primary_ip: "{{ hostvars[groups['infrastructure_nodes'][0]].ansible_host }}"
kubeconfig: "{{ resources_dir }}/kubeconfig.yaml"
values_template: "{{ playbook_dir }}/../values.yaml"
values_file: "{{ resources_dir }}/values.yaml"
- ansible.builtin.shell: |
sed -i "s/127.0.0.1/{{ primary_ip }}/" {{ kubeconfig }}; \
env KUBECONFIG={{ kubeconfig }} kubectl config set-context --namespace=kolab --user=default --cluster=default --current; \
- name: Check kubectl config
ansible.builtin.shell:
cmd: env KUBECONFIG={{ kubeconfig }} kubectl get pods
# - name: Apply primary node label
# ansible.builtin.shell:
# cmd: env KUBECONFIG={{ kubeconfig }} kubectl label nodes {{ hostvars[groups['worker_nodes'][0]].inventory_hostname }} kolab.org/nodegroup=primary
# - name: Apply secondary node label
# ansible.builtin.shell:
# cmd: env KUBECONFIG={{ kubeconfig }} kubectl label nodes {{ hostvars[groups['worker_nodes'][1]].inventory_hostname }} kolab.org/nodegroup=secondary
- name: Prepare k3s
ansible.builtin.shell:
cmd: env KUBECONFIG={{ kubeconfig }} {{ kolabctl_path }} k3s-setup
ignore_errors: true
# Delete existing ingressclass, otherwise we can't apply our chart with the subcharts, which tries to create the same ingressclass
- ansible.builtin.shell:
cmd: env KUBECONFIG={{ kubeconfig }} kubectl delete ingressclass/haproxy
ignore_errors: true
- ansible.builtin.shell:
cmd: env IMAGE_REGISTRY={{ primary_ip }}:5001 IMAGE_VERSION=latest ADMIN_PASSWORD={{ admin_password }} DOMAIN={{ domain }} PUBLIC_IP={{ primary_ip }} TEMPLATE="{{ values_template }}" {{ kolabctl_path }} reconfigure
chdir: "{{ resources_dir }}"
creates: values.yaml
when: local_registry
- ansible.builtin.shell:
cmd: env ADMIN_PASSWORD={{ admin_password }} DOMAIN={{ domain }} PUBLIC_IP={{ primary_ip }} TEMPLATE="{{ values_template }}" {{ kolabctl_path }} reconfigure
chdir: "{{ resources_dir }}"
creates: values.yaml
when: not local_registry
- name: "Deploying kolab"
ansible.builtin.shell:
cmd: env KUBECONFIG={{ kubeconfig }} CHART_URL={{ chart_url }} {{ kolabctl_path }} apply --force
chdir: "{{ resources_dir }}"

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 24, 10:02 AM (6 d, 18 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18845306
Default Alt Text
playbook.yaml (3 KB)

Event Timeline