blob: cd2fb50ea0723748c43b2554126ac4aafcd85fd8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
---
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2018
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
- import_playbook: preconfigure-cmk.yml
- hosts: localhost
pre_tasks:
- name: Load kud variables
include_vars:
file: kud-vars.yml
vars:
cmk_install_host: '{{ inventory_hostname }}'
tasks:
- name: build list of CMK nodes to untaint
set_fact:
cmk_hosts_list: "{{ groups['kube-node'] }}"
- name: generate CMK install yaml file
command: "cp {{ playbook_dir }}/../images/cmk.yaml {{ playbook_dir }}/../images/cmk-{{ cmk_install_host }}.yaml"
- name: customize CMK install yaml file per runtime env
lineinfile:
dest: "{{ playbook_dir }}/../images/cmk-{{ cmk_install_host }}.yaml"
insertafter: "nodeSelectorTerms:"
line: " - matchFields:\n - key: metadata.name\n operator: In\n values:\n - '{{ item }}'"
register: cus_result
with_items:
- "{{ cmk_hosts_list }}"
- name: prepare CMK CPU cores per config file
replace:
dest: "{{ playbook_dir }}/../images/cmk-{{ cmk_install_host }}.yaml"
regexp: '{{ item.pool }}=0'
replace: '{{ item.pool }}={{ item.cores }}'
with_items:
- { pool: 'num-shared-cores', cores: '{{ cmk_shared_num_cores }}' }
- { pool: 'num-exclusive-cores', cores: '{{ cmk_exclusive_num_cores }}' }
- name: install CMK components
command: "/usr/local/bin/kubectl create -f {{ playbook_dir }}/../images/cmk-{{ cmk_install_host }}.yaml"
- name: wait for all cmk daemonset pods to be running
shell: kubectl get pods -n {{ cmk_namespace }} -l name=cmk -o jsonpath={.items[*].status.phase}
register: kubectl_cmk_running
until: "['Running'] == kubectl_cmk_running.stdout.split() | unique"
retries: 50
delay: 5
failed_when: false
- name: create a script to check CMK setup
copy:
dest: "./cmk-check.sh"
content: |
#!/bin/bash
echo
echo "waiting for cmk-nodereport effective"
status=0
while [ $status -ne 1 ]; do
status=$(kubectl get cmk-nodereport | grep ENV | wc -l)
sleep 1
echo not found
done
echo "cmk-nodereport is effective"
- name: judge the runtime environment
set_fact:
cmk_runtime_env: "{{ groups['kube-node'][0] }}"
- debug:
var: cmk_runtime_env
- name: prepare cmk check file
replace:
dest: "./cmk-check.sh"
regexp: 'ENV'
replace: '{{ cmk_runtime_env }}'
- name: Changing perm of "sh", adding "+x"
shell: "chmod +x cmk-check.sh"
args:
warn: false
- name: Run the script and re-evaluate the variable.
command: "./cmk-check.sh"
- name: Clean the script and folder.
file:
path: ./cmk-check.sh
state: absent
- name: untaint nodes
command: kubectl taint node "{{ item }}" cmk-
failed_when: false
register: untaint_result
changed_when: "untaint_result.rc == 0"
when:
- cmk_untaint_required
with_items:
- "{{ cmk_hosts_list }}"
- debug:
var: untaint_result
|