Added pre installation and unindtallation
[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   failed_when: false
21   no_log: True
22
23 - debug:
24     msg: k3s is already present
25   when: result.rc == 0
26
27 - meta: end_play
28   when: result.rc == 0
29
30 - debug: var=ansible_host
31
32 - name: Disabling firewall for successfull k3s installation on CentOs
33   shell:
34     cmd: systemctl stop firewalld
35   when: ansible_facts['distribution'] == "CentOS" and result is failed
36
37 - name: install container-selinux
38   shell:
39     cmd: yum install -y container-selinux selinux-policy-base
40   when: ansible_facts['distribution'] == "CentOS" and result is failed
41   ignore_errors: true
42
43 - name: install k3s-selinux-0.1.1-rc1.el7.noarch.rpm
44   shell:
45     cmd: rpm -i https://rpm.rancher.io/k3s-selinux-0.1.1-rc1.el7.noarch.rpm
46   when: ansible_facts['distribution'] == "CentOS" and result is failed
47   ignore_errors: true
48
49 - name: get interface name
50   shell:
51     cmd: ip a |grep {{ ansible_host }} |awk '{print $NF}'
52   register: ifName
53   when: result is failed
54
55 - name: install k3s
56   shell:
57     cmd: curl -sfL https://get.k3s.io | sh -
58   when: result is failed
59
60 - name: create .kube dir
61   shell:
62     cmd: mkdir -p $HOME/.kube/
63   when: result is failed
64
65 - name: copy kubeconfig
66   shell:
67     cmd: cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
68   when: result is failed