From 51a54da4adba8cc89105a098abc6866deafef36f Mon Sep 17 00:00:00 2001 From: guppy Date: Wed, 10 May 2023 10:21:53 +0200 Subject: [PATCH] Restructuration des roles --- calico.yaml | 6 +++ initialize-kubernetes.yaml | 51 ------------------- openebs.yaml | 19 ++----- pre-join.yaml | 35 +++++++++++++ roles/calico/tasks/main.yaml | 19 +++++++ .../calico/templates}/calico.yaml.j2 | 0 roles/openebs/tasks/main.yaml | 11 ++++ .../openebs/templates}/openebs.yaml | 0 start.yaml | 2 + 9 files changed, 78 insertions(+), 65 deletions(-) create mode 100644 calico.yaml create mode 100644 pre-join.yaml create mode 100644 roles/calico/tasks/main.yaml rename {templates => roles/calico/templates}/calico.yaml.j2 (100%) create mode 100644 roles/openebs/tasks/main.yaml rename {templates => roles/openebs/templates}/openebs.yaml (100%) diff --git a/calico.yaml b/calico.yaml new file mode 100644 index 0000000..77871ac --- /dev/null +++ b/calico.yaml @@ -0,0 +1,6 @@ +--- +- hosts: control-plane + name: "Install Calico CNI" + roles: + - role: calico + run_once: True diff --git a/initialize-kubernetes.yaml b/initialize-kubernetes.yaml index ca506c8..b749190 100644 --- a/initialize-kubernetes.yaml +++ b/initialize-kubernetes.yaml @@ -52,58 +52,7 @@ register: kubectl - debug: var=kubectl.stdout_lines - - name: get calico conf - template: - src: calico.yaml.j2 - dest: $HOME/calico.yaml - - - name: apply calico conf1 - shell: kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/tigera-operator.yaml - register: apply1 - - debug: var=apply1.stdout_lines - - - name: apply calico conf2 - shell: kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/custom-resources.yaml - register: apply2 - - debug: var=apply2.stdout_lines - - - name: apply calico conf3 - shell: kubectl apply -f calico.yaml - register: apply3 - - debug: var=apply3.stdout_lines - - name: show pods command: kubectl get pods --all-namespaces register: pods - debug: var=pods.stdout_lines - - - name: "Cluster token" - shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p' - register: K8S_TOKEN - - - name: "CA Hash" - shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //' - register: K8S_MASTER_CA_HASH - - - name: "IP and port" - shell: kubectl cluster-info | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | cut -d ' ' -f 7 | sed -n '1p' | cut -c 9- - register: K8S_IP_PORT - - - name: "Add K8S Token and Hash to dummy host" - add_host: - name: "K8S_TOKEN_HOLDER" - token: "{{ K8S_TOKEN.stdout }}" - hash: "{{ K8S_MASTER_CA_HASH.stdout }}" - ipport: "{{ K8S_IP_PORT.stdout }}" - - - name: - debug: - msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}" - - - name: - debug: - msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}" - - - name: - debug: - msg: "[Master] K8S_TOKEN_HOLDER K8S IP and port is {{ hostvars['K8S_TOKEN_HOLDER']['ipport'] }}" diff --git a/openebs.yaml b/openebs.yaml index 9bbacbf..41a08d3 100644 --- a/openebs.yaml +++ b/openebs.yaml @@ -1,15 +1,6 @@ --- - - hosts: control-plane - name: "Start OpenEBS" - tasks: - - name: Install openEBS - shell: kubectl apply -f https://openebs.github.io/charts/openebs-operator-lite.yaml - - - name: Copy conf - become: yes - template: - src: openebs.yaml - dest: /etc/openebs.yaml - - - name: Apply Conf - shell: kubectl apply -f /etc/openebs.yaml +- hosts: control-plane + name: "Install OpenEBS Storagee provider" + roles: + - role: openebs + run_once: True diff --git a/pre-join.yaml b/pre-join.yaml new file mode 100644 index 0000000..dce4a61 --- /dev/null +++ b/pre-join.yaml @@ -0,0 +1,35 @@ +--- +- hosts: control-plane + name: "Export token hash and IPPORT for node to join" + + tasks: + - name: "Cluster token" + shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p' + register: K8S_TOKEN + + - name: "CA Hash" + shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //' + register: K8S_MASTER_CA_HASH + + - name: "IP and port" + shell: kubectl cluster-info | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | cut -d ' ' -f 7 | sed -n '1p' | cut -c 9- + register: K8S_IP_PORT + + - name: "Add K8S Token and Hash to dummy host" + add_host: + name: "K8S_TOKEN_HOLDER" + token: "{{ K8S_TOKEN.stdout }}" + hash: "{{ K8S_MASTER_CA_HASH.stdout }}" + ipport: "{{ K8S_IP_PORT.stdout }}" + + - name: + debug: + msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}" + + - name: + debug: + msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}" + + - name: + debug: + msg: "[Master] K8S_TOKEN_HOLDER K8S IP and port is {{ hostvars['K8S_TOKEN_HOLDER']['ipport'] }}" diff --git a/roles/calico/tasks/main.yaml b/roles/calico/tasks/main.yaml new file mode 100644 index 0000000..6f2a5fb --- /dev/null +++ b/roles/calico/tasks/main.yaml @@ -0,0 +1,19 @@ +- name: get calico conf + template: + src: calico.yaml.j2 + dest: $HOME/calico.yaml + +- name: apply calico conf1 + shell: kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/tigera-operator.yaml + register: apply1 +- debug: var=apply1.stdout_lines + +- name: apply calico conf2 + shell: kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.25.1/manifests/custom-resources.yaml + register: apply2 +- debug: var=apply2.stdout_lines + +- name: apply calico conf3 + shell: kubectl apply -f calico.yaml + register: apply3 +- debug: var=apply3.stdout_lines diff --git a/templates/calico.yaml.j2 b/roles/calico/templates/calico.yaml.j2 similarity index 100% rename from templates/calico.yaml.j2 rename to roles/calico/templates/calico.yaml.j2 diff --git a/roles/openebs/tasks/main.yaml b/roles/openebs/tasks/main.yaml new file mode 100644 index 0000000..8aa4296 --- /dev/null +++ b/roles/openebs/tasks/main.yaml @@ -0,0 +1,11 @@ +- name: Install openEBS + shell: kubectl apply -f https://openebs.github.io/charts/openebs-operator-lite.yaml + +- name: Copy conf + become: yes + template: + src: openebs.yaml + dest: /etc/openebs.yaml + +- name: Apply Conf + shell: kubectl apply -f /etc/openebs.yaml diff --git a/templates/openebs.yaml b/roles/openebs/templates/openebs.yaml similarity index 100% rename from templates/openebs.yaml rename to roles/openebs/templates/openebs.yaml diff --git a/start.yaml b/start.yaml index 3c4f8c6..4b66d92 100644 --- a/start.yaml +++ b/start.yaml @@ -1,5 +1,7 @@ --- - import_playbook: initialize-kubernetes.yaml +- import_playbook: calico.yaml +- import_playbook: pre-join.yaml - import_playbook: kubernetes-worker.yaml #- import_playbook: openebs.yaml #- import_playbook: purelb.yaml