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

Checking if Loki plug-in for Docker is present and installing/updating it accordingly #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 29 additions & 13 deletions tasks/monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,34 @@
with_items:
- /data/file-exporter

# TODO : Check if the log plugin is installed, if is
#docker plugin disable loki
#docker plugin upgrade loki grafana/loki-docker-driver:master
#docker plugin enable loki
# and restart docker

- name: Linux Server | Monitoring | Add docker plugin for remote logs
command: docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions
ignore_errors: True
notify: docker configuration changed
# checking for docker/loki presence and installing/updating accordingly
- name: Linux Server | Monitoring | Check if Loki plug-in for Docker is present
shell: if [ $(docker plugin ls | grep -o loki | wc -c) -eq 5 ]; then echo "present"; else echo "absent"; fi
register: loki_state
when: loki is defined

- name: Linux Server | Monitoring | Install Loki plug-in for Docker
shell: docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions
when: loki is defined and loki_state.stdout == 'absent'

- name: Linux Server | Monitoring | Check if Loki plug-in for Docker is enabled
shell: if [ $(docker plugin ls | grep -o true) ]; then echo true; else echo false; fi
register: loki_enabled
when: loki is defined and loki_state.stdout == 'present'

- name: Linux Server | Monitoring | Disable Loki plug-in for Docker
shell: if [ $(docker plugin disable loki | grep -o loki | wc -c) -eq 5 ]; then echo "false"; else echo "true"; fi
register: loki_enabled
when: loki is defined and loki_state.stdout == 'present' and loki_enabled.stdout == 'true'

- name: Linux Server | Monitoring | Upgrade Loki plug-in for Docker
shell: docker plugin upgrade loki grafana/loki-docker-driver:latest --grant-all-permissions
when: loki is defined and loki_state.stdout == 'present' and (loki_enabled.stdout|d('false')) == 'false'

- name: Linux Server | Monitoring | Enable Loki plug-in for Docker
shell: docker plugin enable loki
when: loki is defined and loki_state.stdout == 'present' and (loki_enabled.stdout|d('false')) == 'false'

- name: Linux Server | Monitoring | Setup node exporter
docker_container:
hostname: "{{ hostname + '.' + domain }}"
Expand All @@ -51,7 +67,7 @@
- "/file-exporter"
state: started
restart_policy: unless-stopped
memory: '32m'
memory: "32m"
ports:
- 9100:9100

Expand All @@ -69,7 +85,7 @@
privileged: true
state: started
restart_policy: unless-stopped
memory: '96m'
memory: "96m"
published_ports:
- 9101:8080

Expand Down Expand Up @@ -100,7 +116,7 @@
state: started
restart: true
restart_policy: unless-stopped
memory: '32m'
memory: "32m"
published_ports:
- 9080:9080
when: loki is defined