Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include default vars to filebeat's upgrade role #1878

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
filebeat_helm_chart_name: filebeat
filebeat_helm_chart_file_name: filebeat-7.9.2.tgz
filebeat_version: "7.9.2"
# Use custom namespace for logging charts such as filebeat in case of k8s as cloud service.
# Use dedicated namespace for logging charts such as filebeat in case of k8s as cloud service.
logging_chart_namespace: epi-logging
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
command: |
helm -n {{ logging_chart_namespace }} upgrade --install \
-f {{ download_directory }}/custom-chart-values.yml \
{{ specification.helm_chart_name }} \
{{ filebeat_helm_chart_name }} \
{{ download_directory }}/{{ filebeat_helm_chart_file_name }} --create-namespace
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---

- name: Uninstall Helm release "{{ specification.helm_chart_name }}"
- name: Uninstall Helm release "{{ filebeat_helm_chart_name }}"

delegate_to: localhost
become: false
run_once: true

command: helm uninstall {{ specification.helm_chart_name }}
command: helm uninstall {{ filebeat_helm_chart_name }}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ exporter:
service:
description: "Service that runs Prometheus Node Exporter"
name: prometheus-node-exporter
# Use custom namespace for monitoring charts such as node exporter in case of k8s as cloud service.
node_exporter_helm_chart_name: node-exporter
# Use dedicated namespace for monitoring charts such as node exporter in case of k8s as cloud service.
monitoring_chart_namespace: epi-monitoring
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
- name: Copy Node-Exporter's Helm chart's custom configuration to file
copy:
content: "{{ specification.helm_chart_values }}"
dest: "{{ download_directory }}/{{ specification.helm_chart_name }}_values.yaml"
dest: "{{ download_directory }}/{{ node_exporter_helm_chart_name }}_values.yaml"

- name: Install Node-Exporter's Helm chart (with custom values.yaml)
delegate_to: localhost
shell: |
helm -n {{ monitoring_chart_namespace }} upgrade --install \
-f {{ download_directory }}/{{ specification.helm_chart_name }}_values.yaml \
{{ specification.helm_chart_name }} \
-f {{ download_directory }}/{{ node_exporter_helm_chart_name }}_values.yaml \
{{ node_exporter_helm_chart_name }} \
{{ download_directory }}/{{ exporter_chart_file_name }} --create-namespace

- when: not helm_chart_values_bool
Expand All @@ -47,5 +47,5 @@
- name: Install Node-Exporter's Helm chart (with default values.yaml)
shell: |
helm -n {{ monitoring_chart_namespace }} upgrade --install \
{{ specification.helm_chart_name }} \
{{ node_exporter_helm_chart_name }} \
{{ download_directory }}/{{ exporter_chart_file_name }} --create-namespace
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
owner: root
group: root
mode: u=rw,g=r,o=r
vars:
exporter_service_description: "{{ exporter.service.description }}"

- name: Configure systemd to use node_exporter service
systemd:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---

- name: Uninstall Helm release "{{ specification.helm_chart_name }}"
- name: Uninstall Helm release "{{ node_exporter_helm_chart_name }}"

delegate_to: localhost
become: false
run_once: true

command: helm uninstall {{ specification.helm_chart_name }}
command: helm uninstall {{ node_exporter_helm_chart_name }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#jinja2: trim_blocks:False
[Unit]
Description={{ exporter.service.description }}
Description={{ exporter_service_description }}

[Service]
User=node_exporter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
---
- name: Filebeat as DaemonSet | Prepare fact about helm release
- name: Filebeat | Load defaults from filebeat role
include_vars:
file: roles/filebeat/defaults/main.yml
name: filebeat_defaults

- name: Filebeat as DaemonSet | Prepare fact about helm release and reinstall daemonset if release exists
delegate_to: localhost
become: false
run_once: true
when:
- k8s_as_cloud_service is defined
- k8s_as_cloud_service
block:
- name: Get information about helm releases
command: helm list --output json
Expand All @@ -16,24 +24,22 @@
_names: >-
{{ helm_list.stdout | from_json
| map(attribute='name')
| select('==', specification.helm_chart_name)
| select('==', filebeat_defaults.filebeat_helm_chart_name)
| list }}

- name: Reinstall Filebeat as DaemonSet from default namespace to custom namespace for "k8s as cloud service"
when:
- filebeat_release_exists
- k8s_as_cloud_service is defined
- k8s_as_cloud_service
block:
- name: Include uninstall task for Filebeat as DaemonSet in default namespace for "k8s as cloud service"
include_role:
name: filebeat
tasks_from: uninstall-filebeat-as-daemonset.yml
- name: Reinstall Filebeat as DaemonSet from default namespace to dedicated namespace for "k8s as cloud service"
when:
- filebeat_release_exists
block:
- name: Include uninstall task for Filebeat as DaemonSet in default namespace for "k8s as cloud service"
include_role:
name: filebeat
tasks_from: uninstall-filebeat-as-daemonset.yml

- name: Include install task for Filebeat as DaemonSet in custom namespace for "k8s as cloud service"
include_role:
name: filebeat
tasks_from: install-filebeat-as-daemonset.yml
- name: Include install task for Filebeat as DaemonSet in dedicated namespace for "k8s as cloud service"
include_role:
name: filebeat
tasks_from: install-filebeat-as-daemonset.yml

- name: Filebeat as System Service | Get information about installed packages as facts
package_facts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
- name: Node Exporter | Include defaults from node_exporter role
include_vars:
file: roles/node_exporter/defaults/main.yml
name: exporter_defaults

- name: Node Exporter | Include specification vars from node_exporter role
include_vars:
file: roles/node_exporter/vars/main.yml

- name: Node Exporter as DaemonSet | Prepare fact about helm release
- name: Node Exporter as DaemonSet | Prepare fact about helm release and reinstall daemonset if release exists
delegate_to: localhost
become: false
run_once: true
when:
- k8s_as_cloud_service is defined
- k8s_as_cloud_service
block:
- name: Get information about helm releases
command: helm list --output json
Expand All @@ -24,38 +28,36 @@
_names: >-
{{ helm_list.stdout | from_json
| map(attribute='name')
| select('==', specification.helm_chart_name)
| select('==', exporter_defaults.node_exporter_helm_chart_name)
| list }}

- name: Reinstall Node Exporter as DaemonSet from default namespace to custom namespace for "k8s as cloud service"
when:
- node_exporter_release_exists
- k8s_as_cloud_service is defined
- k8s_as_cloud_service
block:
- name: Include uninstall task for Node Exporter as DaemonSet in default namespace for "k8s as cloud service"
include_role:
name: node_exporter
tasks_from: uninstall-node-exporter-as-daemonset.yml
- name: Reinstall Node Exporter as DaemonSet from default namespace to dedicated namespace for "k8s as cloud service"
when:
- node_exporter_release_exists
block:
- name: Include uninstall task for Node Exporter as DaemonSet in default namespace for "k8s as cloud service"
include_role:
name: node_exporter
tasks_from: uninstall-node-exporter-as-daemonset.yml

- name: Include install task for Node Exporter as DaemonSet in custom namespace for "k8s as cloud service"
include_role:
name: node_exporter
tasks_from: install-node-exporter-as-daemonset.yml
- name: Include install task for Node Exporter as DaemonSet in dedicated namespace for "k8s as cloud service"
include_role:
name: node_exporter
tasks_from: install-node-exporter-as-daemonset.yml

- name: Node Exporter as System Service | Populate service facts
service_facts:
when: ansible_facts.services is undefined

- name: Node Exporter as System Service | Test if node exporter service is configured
assert:
that: "'{{ exporter.service.name }}.service' in ansible_facts.services"
fail_msg: "{{ exporter.service.name }} service is not found"
that: "'{{ exporter_defaults.exporter.service.name }}.service' in ansible_facts.services"
fail_msg: "{{ exporter_defaults.exporter.service.name }} service is not found"
quiet: true

- name: Node Exporter as System Service | Set exporter_file_name fact
set_fact:
exporter_file_name: "node_exporter-{{ exporter.version }}.linux-amd64.tar.gz"
exporter_file_name: "node_exporter-{{ exporter_defaults.exporter.version }}.linux-amd64.tar.gz"

- name: Node Exporter as System Service | Collect version
shell: >-
Expand All @@ -70,10 +72,10 @@
debug:
msg:
- "Installed version: {{ exporter_current_version }}"
- "Target version: {{ exporter.version }}"
- "Target version: {{ exporter_defaults.exporter.version }}"

- name: Node Exporter as System Service | Upgrade block
when: exporter.version != exporter_current_version
when: exporter_defaults.exporter.version != exporter_current_version
block:
- name: Node Exporter | Download binaries
include_role:
Expand All @@ -84,7 +86,7 @@

- name: Node Exporter as System Service | Stop exporter
systemd:
name: "{{ exporter.service.name }}.service"
name: "{{ exporter_defaults.exporter.service.name }}.service"
state: stopped

- name: Node Exporter as System Service | Remove /opt/node_exporter directory
Expand Down Expand Up @@ -115,14 +117,16 @@
- name: Node Exporter as System Service | Update systemd service configuration
template:
src: roles/node_exporter/templates/prometheus-node-exporter.service.j2
dest: "/etc/systemd/system/{{ exporter.service.name }}.service"
dest: "/etc/systemd/system/{{ exporter_defaults.exporter.service.name }}.service"
owner: root
group: root
mode: '0644'
vars:
exporter_service_description: "{{ exporter_defaults.exporter.service.description }}"

- name: Node Exporter as System Service | Start exporter
systemd:
daemon_reload: true
enabled: true
name: "{{ exporter.service.name }}.service"
name: "{{ exporter_defaults.exporter.service.name }}.service"
state: started
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ kind: configuration/filebeat
title: Filebeat
name: default
specification:
helm_chart_name: filebeat
disable_helm_chart: false
postgresql_input:
multiline:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ kind: configuration/node-exporter
title: "Node exporter"
name: default
specification:
helm_chart_name: node-exporter
disable_helm_chart: false
helm_chart_values:
service:
Expand Down