70cde7ca1717f94e786aaf692902452f2e8b7b06
[ealt-edge.git] / ocd / infra / playbooks / roles / k3s / tasks / install.yml
1 # Copyright 2020 Huawei Technologies Co., Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 ---
16 - name: check whether k3s is already installed
17   shell:
18     cmd: which k3s
19   register: result
20   ignore_errors: yes
21   no_log: True
22
23 - debug:
24     msg: k3s is already present
25   when: result.stdout != ""
26
27 - debug:
28 # yamllint disable rule:line-length
29     msg: Ignore Uninstall Log , k3s not installed continue with Installation
30 # yamllint disable rule:line-length
31   when: result.stdout == ""
32
33 - debug: var=ansible_host
34
35 - name: "INSTALL: Disabling firewall for successfull k3s installation on CentOs"
36   shell:
37     cmd: systemctl stop firewalld
38   when: ansible_facts['distribution'] == "CentOS" and result is failed
39
40 - name: "INSTALL: install container-selinux"
41   shell:
42     cmd: yum install -y container-selinux selinux-policy-base
43   when: ansible_facts['distribution'] == "CentOS" and result is failed
44   ignore_errors: true
45
46 - name: "INSTALL: install k3s-selinux-0.1.1-rc1.el7.noarch.rpm"
47   shell:
48     cmd: rpm -i https://rpm.rancher.io/k3s-selinux-0.1.1-rc1.el7.noarch.rpm
49   when: ansible_facts['distribution'] == "CentOS" and result is failed
50   ignore_errors: true
51
52 - name: "INSTALL: get interface name"
53   shell:
54     cmd: ip a |grep {{ ansible_host }} |awk '{print $NF}'
55   register: ifName
56   when: result is failed
57
58 # yamllint disable rule:line-length
59 - name: "INSTALL: install k3s"
60   shell:
61     cmd: curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--node-ip={{ ansible_host }} --node-external-ip={{ ansible_host }} --bind-address={{ ansible_host }} --flannel-iface=eth0 --docker --no-deploy=servicelb --no-deploy=traefik --write-kubeconfig-mode 644 --kube-apiserver-arg="service-node-port-range=30000-36000"" sh -
62   when: result is failed
63
64 # yamllint disable rule:line-length
65
66 #- name: "INSTALL: install k3s"
67 # shell:
68 #    cmd: curl -sfL https://get.k3s.io | sh -
69 #  when: result is failed
70
71 - name: "INSTALL: create .kube dir"
72   shell:
73     cmd: mkdir -p $HOME/.kube/
74   when: result is failed
75
76 - name: "INSTALL: copy kubeconfig"
77   shell:
78     cmd: cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
79   when: result is failed