2022-12-14 02:23:34 +01:00
|
|
|
- hosts: odroid_master
|
|
|
|
name: Install k3s
|
|
|
|
become: true
|
2023-10-26 19:19:10 +02:00
|
|
|
gather_facts: no
|
2022-12-14 02:23:34 +01:00
|
|
|
tasks:
|
|
|
|
- name: Install K3S
|
|
|
|
ansible.builtin.shell: 'curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_VERSION="v1.24.1+k3s1" sh -s -'
|
2023-10-24 00:11:12 +02:00
|
|
|
#changed_when: false
|
2022-12-14 02:23:34 +01:00
|
|
|
- name: Get token
|
|
|
|
ansible.builtin.command: 'cat /var/lib/rancher/k3s/server/node-token'
|
|
|
|
register: k3s_token
|
|
|
|
changed_when: false
|
|
|
|
- name: Print token
|
|
|
|
ansible.builtin.debug: var=k3s_token.stdout
|
|
|
|
- name: "Add K8S Token and Hash to dummy host"
|
|
|
|
ansible.builtin.add_host:
|
|
|
|
name: "K3S_TOKEN_HOLDER"
|
|
|
|
token: "{{ k3s_token.stdout }}"
|
|
|
|
- name: Print token
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "[Master] K3S_TOKEN_HOLDER K8S token is {{ hostvars['K3S_TOKEN_HOLDER']['token'] }}"
|
|
|
|
- name: Grant cluster role
|
|
|
|
ansible.builtin.command: kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user root
|
|
|
|
changed_when: false
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- name: Reboot the server
|
|
|
|
tags: reboot
|
|
|
|
become: yes
|
|
|
|
become_user: root
|
|
|
|
shell: "sleep 5 && reboot"
|
|
|
|
async: 1
|
|
|
|
poll: 0
|
|
|
|
|
|
|
|
- name: (reboot) Wait for server to restart
|
|
|
|
wait_for_connection:
|
|
|
|
delay: 75
|
2023-10-23 10:52:53 +02:00
|
|
|
- name: Wait for service 'k3s.service' to be running
|
2022-12-14 02:23:34 +01:00
|
|
|
service_facts:
|
|
|
|
register: result
|
|
|
|
until: result.ansible_facts.services['k3s.service'].state == 'running'
|
|
|
|
retries: 10
|
|
|
|
delay: 5
|
|
|
|
#create cluster:
|
|
|
|
#curl -u "token-wg66j:p26nwqs9ckqbth4h8gtfd2g7858g8smbtpgmxq9qr52w4795l5jvv9" -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{"name":"test-cluster"}' 'https://192.168.77.106:8543/v3/clusters' --insecure
|
|
|
|
#get registration token
|
|
|
|
# curl -u "token-wg66j:p26nwqs9ckqbth4h8gtfd2g7858g8smbtpgmxq9qr52w4795l5jvv9" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' https://192.168.77.106:8543/v3/clusters/c-xq5pv/clusterRegistrationTokens --insecure|jq
|
|
|
|
- name: Create new cluster in rancher
|
2023-10-23 10:52:53 +02:00
|
|
|
ansible.builtin.shell: "curl -u '{{ rancher_api_key }}' -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{\"name\":\"odroid\"}' 'https://192.168.77.106:8543/v3/clusters' --insecure| jq .id"
|
2022-12-14 02:23:34 +01:00
|
|
|
changed_when: false
|
|
|
|
ignore_errors: true
|
|
|
|
register: cluster_id
|
|
|
|
|
|
|
|
- name: Just the Names
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "{{ cluster_id.stdout }}"
|
|
|
|
- name: Create new cluster in rancher
|
2023-10-23 10:52:53 +02:00
|
|
|
ansible.builtin.shell: "curl -u '{{ rancher_api_key }}' -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' https://192.168.77.106:8543/v3/clusters/{{ cluster_id.stdout }}/clusterRegistrationTokens --insecure| jq .data[0].manifestUrl"
|
2022-12-14 02:23:34 +01:00
|
|
|
changed_when: false
|
|
|
|
ignore_errors: true
|
|
|
|
register: register_id
|
|
|
|
- name: Register Token
|
|
|
|
ansible.builtin.debug:
|
|
|
|
msg: "{{ register_id.stdout }}"
|
|
|
|
- name: "Register in Rancher"
|
|
|
|
ansible.builtin.shell: "curl --insecure -sfL {{ register_id.stdout }} |sed 's/rancher-agent:v2.6.7/rancher-agent:v2.6.7-linux-arm64/g'| sed 's%beta.kubernetes.io/os%kubernetes.io/os%g'| kubectl apply -f -"
|
|
|
|
changed_when: false
|
|
|
|
ignore_errors: true
|
|
|
|
# - name: "Register in Rancher"
|
|
|
|
# ansible.builtin.shell: curl --insecure -sfL https://192.168.77.106:8543/v3/import/f5679ncdtx68489nqj2rntk8bwv6lcsq4j5qdtnxswkbfbtttn5s5q_c-lq4j4.yaml |sed 's/rancher-agent:v2.6.7/rancher-agent:v2.6.7-linux-arm64/g'| sed 's%beta.kubernetes.io/os%kubernetes.io/os%g'| kubectl apply -f -
|
|
|
|
# changed_when: false
|
|
|
|
# ignore_errors: true
|
2022-12-16 22:09:02 +01:00
|
|
|
- name: wait for pods to come up
|
|
|
|
shell: kubectl get pods -o json -n cattle-system
|
|
|
|
register: kubectl_get_pods
|
|
|
|
until: kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == ["Running"]
|
|
|
|
retries: 20
|
|
|
|
delay: 30
|