aboutsummaryrefslogtreecommitdiffstats
path: root/kud/deployment_infra/playbooks/configure-emco.yml
blob: b3266b7060294582c4d25fb5674125b50b89324e (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
# 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
##############################################################################

- hosts: localhost
  become: yes
  tasks:
    - name: Load kud variables
      include_vars:
        file: kud-vars.yml

    - name: Getting emco code in /opt folder
      git:
        repo: "{{ emco_git_url }}"
        version: "{{ emco_version }}"
        dest: "{{ emco_dir }}"
        depth: 1
        force: yes

    - name: Install make package for Ubuntu systems
      apt: name=make state=present update_cache=yes
      when: ansible_distribution == "Ubuntu"

    - name: Install make package for CentOS systems
      yum: name=make state=present update_cache=yes
      when: ansible_distribution == "CentOS"

    - name: Create emco namespace
      shell: "/usr/local/bin/kubectl create namespace emco"
      ignore_errors: True

    - name: Create pod security policy role bindings
      shell: "/usr/local/bin/kubectl -n emco create rolebinding psp:default:privileged --clusterrole=psp:privileged --serviceaccount=emco:default --serviceaccount=emco:emco-fluentd --serviceaccount=emco:monitor"
      ignore_errors: True

    - name: Set artifacts_dir fact
      set_fact:
        artifacts_dir: "{{ hostvars[groups['kube-master'][0]]['inventory_dir'] }}/artifacts"

    - name: Make emco helm charts
      command: /usr/bin/make all
      args:
        chdir: "{{ emco_dir }}/deployments/helm/emcoOpenNESS"
      when: "'emco' in emco_roles"

    - name: Get cluster name
      shell: "/usr/local/bin/kubectl -n kube-system get configmap/kubeadm-config -o yaml | grep clusterName: | awk '{print $2}'"
      register: cluster_name
      when: "'emco' in emco_roles"

    - name: Create helm override values
      copy:
        dest: "{{ emco_dir }}/deployments/helm/emcoOpenNESS/helm_value_overrides.yaml"
        content: |
          {{ emco_values | to_nice_yaml(indent=2) }}
      when: "'emco' in emco_roles"

    - name: Install emco helm charts
      command: /usr/local/bin/helm install --wait --timeout 10m --namespace emco -f helm_value_overrides.yaml --set emco-db.etcd.clusterDomain={{ cluster_name.stdout }} --set emco-tools.fluentd.clusterDomain={{ cluster_name.stdout }} emco dist/packages/emco-0.1.0.tgz
      args:
        chdir: "{{ emco_dir }}/deployments/helm/emcoOpenNESS"
      when: "'emco' in emco_roles"

    - name: Apply patch to emcoctl
      patch:
        src: emcoctl-openness-21.03.patch
        basedir: "{{ emco_dir }}"
        strip: 1
      when: emco_version == "openness-21.03"

    - name: Make emcoctl
      command: /usr/bin/make
      args:
        chdir: "{{ emco_dir }}/src/tools/emcoctl"
      when: "'emco' in emco_roles"

    - name: Get emco host address
      shell: "/usr/local/bin/kubectl -n kube-system get configmap/kubeadm-config -o yaml | awk '/advertiseAddress:/ {print $2;exit}'"
      register: emco_host
      when: "'emco' in emco_roles"

    - name: Write emcoctl config on ansible host
      template:
        src: emcoconfig.yaml.j2
        dest: "{{ artifacts_dir }}/emcoconfig.yaml"
        mode: 0640
      become: no
      run_once: yes
      vars:
        host: "{{ emco_host.stdout }}"
      when:
      - emcoconfig_localhost
      - "'emco' in emco_roles"

    - name: Copy emcoctl binary to ansible host
      copy:
        src: "{{ emco_dir }}/bin/emcoctl/emcoctl"
        dest: "{{ artifacts_dir }}/emcoctl"
        mode: 0755
      become: no
      run_once: yes
      when:
      - emcoctl_localhost
      - "'emco' in emco_roles"

    - name: Create helper script emcoctl.sh on ansible host
      copy:
        content: |
          #!/bin/bash
          ${BASH_SOURCE%/*}/emcoctl --config ${BASH_SOURCE%/*}/emcoconfig.yaml "$@"
        dest: "{{ artifacts_dir }}/emcoctl.sh"
        mode: 0755
      become: no
      run_once: yes
      when:
      - emcoctl_localhost
      - emcoconfig_localhost
      - "'emco' in emco_roles"

    - name: Apply patch to monitor chart
      patch:
        src: emco-monitor-openness-21.03.patch
        basedir: "{{ emco_dir }}"
        strip: 1
      when:
      - emco_version == "openness-21.03"
      - "'monitor' in emco_roles"

    - name: Package monitor chart
      command: /usr/local/bin/helm package monitor
      args:
        chdir: "{{ emco_dir }}/deployments/helm"
      when: "'monitor' in emco_roles"

    - name: Install monitor helm chart
      command: /usr/local/bin/helm install --wait --namespace emco --set registryPrefix={{ emco_repository }} --set tag={{ emco_version }} monitor monitor-0.1.0.tgz
      args:
        chdir: "{{ emco_dir }}/deployments/helm"
      when: "'monitor' in emco_roles"

- hosts: kube-master
  become: yes
  tasks:
    - name: Load kud variables
      include_vars:
        file: kud-vars.yml

    - name: Get emco host address
      shell: "/usr/local/bin/kubectl -n kube-system get configmap/kubeadm-config -o yaml | grep advertiseAddress: | awk '{print $2}'"
      register: emco_host
      when: "'emco' in emco_roles"

    - name: Install emcoctl config
      template:
        src: emcoconfig.yaml.j2
        dest: "~/.emco.yaml"
        mode: 0640
      become: no
      run_once: yes
      vars:
        host: "{{ emco_host.stdout }}"
      when: "'emco' in emco_roles"

    - name: Install emcoctl
      copy:
        src: "{{ emco_dir }}/bin/emcoctl/emcoctl"
        dest: "/usr/local/bin/emcoctl"
        mode: 0755
      when: "'emco' in emco_roles"