aboutsummaryrefslogtreecommitdiffstats
path: root/kud/deployment_infra/playbooks/configure-cmk.yml
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
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function *
---
# 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