ansible-debops-infrastructure

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.erethon.com/ansible-debops-infrastructure
Log | Files | Refs

commit 45e51bd13bc3cb9c044dfbebf8094bc745a455e1
parent d9c569da1ae8c905bf0fba8a5b202077b25009fe
Author: Dionysis Grigoropoulos <dgrig@erethon.com>
Date:   Sun,  3 Jun 2018 19:51:06 +0300

monitoring: Init role, only works on linux systemd

Diffstat:
ansible/inventory/group_vars/all/monitoring.yml | 5+++++
ansible/inventory/host_vars/spinny/monitoring.yml | 3+++
ansible/roles/monitoring/files/node_exporter.service | 10++++++++++
ansible/roles/monitoring/tasks/main.yml | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ansible/roles/monitoring/templates/sysconfig.node_exporter.j2 | 1+
5 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/ansible/inventory/group_vars/all/monitoring.yml b/ansible/inventory/group_vars/all/monitoring.yml @@ -0,0 +1,5 @@ +--- + +node_exporter__bundle: https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz +node_exporter__checksum: "sha256:e92a601a5ef4f77cce967266b488a978711dabc527a720bea26505cba426c029" +node_exporter__listen_address: "{{ ansible_host }}" diff --git a/ansible/inventory/host_vars/spinny/monitoring.yml b/ansible/inventory/host_vars/spinny/monitoring.yml @@ -0,0 +1,3 @@ +--- + +node_exporter__listen_address: "192.168.122.1" diff --git a/ansible/roles/monitoring/files/node_exporter.service b/ansible/roles/monitoring/files/node_exporter.service @@ -0,0 +1,10 @@ +[Unit] +Description=Node Exporter + +[Service] +User=node_exporter +EnvironmentFile=/etc/default/node_exporter +ExecStart=/usr/sbin/node_exporter $OPTIONS + +[Install] +WantedBy=multi-user.target diff --git a/ansible/roles/monitoring/tasks/main.yml b/ansible/roles/monitoring/tasks/main.yml @@ -0,0 +1,63 @@ +--- + +- name: Download node_exporter + get_url: + url: "{{ node_exporter__bundle }}" + dest: /tmp/node_exporter.tar.gz + checksum: "{{ node_exporter__checksum }}" + +- file: + path: /tmp/node_exporter/ + state: directory + +- name: Extract node exporter bundle + unarchive: + src: /tmp/node_exporter.tar.gz + dest: /tmp/node_exporter + remote_src: yes + list_files: yes + register: unarchived_files + +- name: Copy node_exporter to /usr/sbin/ + copy: + src: "/tmp/node_exporter/{{ unarchived_files.files[0] }}/node_exporter" + dest: "/usr/sbin/" + remote_src: yes + owner: root + group: root + mode: 0755 + +- name: Delete /tmp/node_exporter + file: + path: /tmp/node_exporter + state: absent + +- name: Create node_exporter system user + user: + name: node_exporter + create_home: no + system: yes + shell: "/sbin/nologin" + +- name: Copy systemd unit file + copy: + src: node_exporter.service + dest: /etc/systemd/system/ + owner: root + group: root + mode: 0644 + +- name: Copy systemd environment file + template: + src: sysconfig.node_exporter.j2 + dest: /etc/default/node_exporter + owner: root + group: root + mode: 0644 + +- name: Enable node_exporter systemd service + systemd: + name: node_exporter + daemon_reload: yes + state: restarted + enabled: yes diff --git a/ansible/roles/monitoring/templates/sysconfig.node_exporter.j2 b/ansible/roles/monitoring/templates/sysconfig.node_exporter.j2 @@ -0,0 +1 @@ +OPTIONS="--web.listen-address={{ node_exporter__listen_address }}:9100"