diff --git a/tasks/monitoring.yml b/tasks/monitoring.yml index 1c49174..c732537 100644 --- a/tasks/monitoring.yml +++ b/tasks/monitoring.yml @@ -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 }}" @@ -51,7 +67,7 @@ - "/file-exporter" state: started restart_policy: unless-stopped - memory: '32m' + memory: "32m" ports: - 9100:9100 @@ -69,7 +85,7 @@ privileged: true state: started restart_policy: unless-stopped - memory: '96m' + memory: "96m" published_ports: - 9101:8080 @@ -100,7 +116,7 @@ state: started restart: true restart_policy: unless-stopped - memory: '32m' + memory: "32m" published_ports: - 9080:9080 when: loki is defined