From 83bc4f13cba4d840140e55f2dfa5a63990497076 Mon Sep 17 00:00:00 2001 From: Zolfa Date: Sun, 3 May 2020 18:53:08 +0200 Subject: [PATCH] roles/nginx: new monitoring formats --- roles/nginx/defaults/main.yml | 1 + roles/nginx/tasks/main.yaml | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/roles/nginx/defaults/main.yml b/roles/nginx/defaults/main.yml index 09db559..31fbb9a 100644 --- a/roles/nginx/defaults/main.yml +++ b/roles/nginx/defaults/main.yml @@ -1,4 +1,5 @@ --- +host_fqdn: '{{ ansible_hostname }}.dmz.{{ domain }}' server_fqdn: '{{ ansible_hostname }}.{{ domain }}' # Accept HTTPS over PROXY PROTOCOL on Alternate Port: 10443 proxy_protocol: true diff --git a/roles/nginx/tasks/main.yaml b/roles/nginx/tasks/main.yaml index 0bc91cb..b68c4d9 100644 --- a/roles/nginx/tasks/main.yaml +++ b/roles/nginx/tasks/main.yaml @@ -35,4 +35,31 @@ dest: '/etc/nginx/sites-enabled/{{ server_fqdn }}.conf' state: 'link' notify: 'restart nginx' + +- name: 'MONITORNIG | add service HTTP/{{ server_fqdn }}' + block: + - name: 'MONITORING | fetch monitored HTTP for current host' + set_fact: + vhosts: > + {{ hostvars[monitoring_host]['monitoring_facts'][host_fqdn]['vhosts'] + | default([]) }} + - name: 'MONITORING | add HTTP/{{ server_fqdn }} to monitored service' + set_fact: + nginx_monitoring_entry: > + {{ { + host_fqdn: { + 'address': ansible_host, + 'vhosts': vhosts + [server_fqdn], + } + } }} + - name: 'MONITORING | update monitoring facts' + set_fact: + monitoring_facts: > + {{ hostvars[monitoring_host]['monitoring_facts'] + | default({}) + | combine(nginx_monitoring_entry, recursive=true) }} + delegate_facts: true + delegate_to: '{{ monitoring_host }}' + tags: + - 'monitoring' ...