Wolfgang Kulhanek
2020-03-14 1d687af25e920f5913b05853ba6b4c8c330b5690
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
---
- name: Set up ocp4_workload_logging combined dictionary
  set_fact:
    ocp4_workload_logging: >-
      {{ ocp4_workload_logging_defaults
       | combine(ocp4_workload_logging_vars    | default( {} ),
                 ocp4_workload_logging_secrets | default( {}), recursive=true )
      }}
- name: Print combined role variables
  debug:
    var: ocp4_workload_logging
    verbosity: 2
 
- name: Check if Elasticsearch Operator is already installed
  k8s_facts:
    api_version: v1
    kind: Deployment
    namespace: "openshift-operators-redhat"
    name: "elasticsearch-operator"
  register: r_eo_deployment_exists
 
- name: Install Elasticsearch Operator if not installed
  when: r_eo_deployment_exists.resources | length | int == 0
  block:
  - name: Get current stable channel for Elasticsearch
    k8s_facts:
      api_version: packages.operators.coreos.com/v1
      kind: PackageManifest
      name: elasticsearch-operator
      namespace: openshift-marketplace
    register: r_eo_channel
  - name: Set Elasticsearch channel
    set_fact:
      logging_elasticsearch_channel: "{{ r_eo_channel.resources[0].status.defaultChannel }}"  
 
  - name: Print Elasticsearch channel to be installed
    debug:
      msg: "Elasticsearch channel to be installed: {{ logging_elasticsearch_channel }}"
 
  - name: Install Elasticsearch operator prerequisites
    k8s:
      state: present
      definition: "{{ lookup('file', item ) | from_yaml }}"
    loop:
    - ./files/eo_namespace.yaml
    - ./files/eo_operatorgroup.yaml
    - ./files/eo_role.yaml
    - ./files/eo_rolebinding.yaml
 
  - name: Install Elasticsearch operator
    k8s:
      state: present
      definition: "{{ lookup('template', item ) | from_yaml }}"
    loop:
    - ./templates/eo_subscription.j2
 
  - name: Wait for Elasticsearch operator to be ready
    k8s_facts:
      api_version: v1
      kind: Deployment
      namespace: "openshift-operators-redhat"
      name: "elasticsearch-operator"
    register: r_eo_deployment
    retries: 30
    delay: 10
    until:
    - r_eo_deployment.resources | length | int > 0
    - r_eo_deployment.resources[0].status.availableReplicas is defined
    - r_eo_deployment.resources[0].status.availableReplicas | int == r_eo_deployment.resources[0].spec.replicas | int
 
- name: Get current stable channel for Cluster Logging
  k8s_facts:
    api_version: packages.operators.coreos.com/v1
    kind: PackageManifest
    name: cluster-logging
    namespace: openshift-marketplace
  register: r_logging_channel
- name: Set Cluster Logging channel
  set_fact:
    logging_channel: "{{ r_logging_channel.resources[0].status.defaultChannel }}"  
 
- name: Print Cluster Logging channel to be installed
  debug:
    msg: "Cluster Logging channel to be installed: {{ logging_channel }}"
 
- name: Install OpenShift Logging Operator Prerequisites
  k8s:
    state: present
    definition: "{{ lookup('file', item ) | from_yaml }}"
  loop:
  - ./files/logging_namespace.yaml
  - ./files/logging_operatorgroup.yaml
  - ./files/logging_curator_configmap.yaml
 
- name: Install OpenShift Logging Operator
  k8s:
    state: present
    definition: "{{ lookup('template', item ) | from_yaml }}"
  loop:
  - ./templates/logging_subscription.j2
 
- name: Wait for Cluster Logging Operator to be ready
  k8s_facts:
    api_version: v1
    kind: Deployment
    namespace: "openshift-logging"
    name: "cluster-logging-operator"
  register: r_logging_deployment
  retries: 30
  delay: 10
  until:
  - r_logging_deployment.resources | length | int > 0
  - r_logging_deployment.resources[0].status.availableReplicas is defined
  - r_logging_deployment.resources[0].status.availableReplicas | int == r_logging_deployment.resources[0].spec.replicas | int
 
- name: Create OpenShift ClusterLogging
  k8s:
    state: present
    definition: "{{ lookup('template', item ) | from_yaml }}"
  loop:
  - ./templates/cluster_logging.j2
 
- name: Wait until Elasticsearch cluster status is green
  k8s_facts:
    api_version: logging.openshift.io/v1
    kind: ClusterLogging
    name: instance
    namespace: openshift-logging
  register: r_logging
  retries: 30
  delay: 10
  ignore_errors: yes
  until: 
  - r_logging.resources[0].status.logStore.elasticsearchStatus[0].cluster.status is defined
  - r_logging.resources[0].status.logStore.elasticsearchStatus[0].cluster.status == "green"
 
# Leave this as the last task in the playbook.
- name: workload tasks complete
  debug:
    msg: "Workload Tasks completed successfully."
  when: not silent|bool