Commit 532fba24 authored by Pullyvan Krishnamoorthy's avatar Pullyvan Krishnamoorthy
Browse files

add Centos 7, Ubuntu 18.04 and Ubuntu 20.04 selection checked in main.yml playbook

parents
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
\ No newline at end of file
Ansible node_exporter
=========
This role will install a prometheus node_exporter (v0.18.1) on an ubuntu machine
Requirements
------------
Running on a Debian machine (64 bits) using systemd.
Role Variables
--------------
No variables available at the moment
Dependencies
------------
None
Example Playbook
----------------
```yaml
---
- hosts: all
tasks:
- block:
- name: prometheus node exporter
include_role:
name: prometheus_node_exporter
become: yes
```
---
# defaults file for prometheus_node_exporter
\ No newline at end of file
---
# handlers file for prometheus_node_exporter
\ No newline at end of file
install_date: Tue Jan 18 13:34:30 2022
version: ''
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.9
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
\ No newline at end of file
---
- name: create the node_exporter account
user:
create_home: false
name: node_exporter
shell: "/bin/false"
- name: Download node_exporter
get_url:
url: https://copr.fedorainfracloud.org/coprs/ibotty/prometheus-exporters/repo/epel-7/ibotty-prometheus-exporters-epel-7.repo
dest: /etc/yum.repos.d/_copr_ibotty-prometheus-exporters.repo
- name: Install the 'node_exporter'
yum:
name: "node_exporter"
state: present
- name: deploy the service definition file
template:
dest: /etc/systemd/system/node_exporter.service
src: node_exporter_centos.service
- name: deploy additional service options config file
template:
dest: /etc/nodeexport.conf
src: nodeexport.conf
- name: reload systemd to take the new service into account
systemd:
daemon_reload: yes
enabled: yes
name: node_exporter
state: started
---
# tasks file for ansible_node_exporter
- include: ubuntu18.yml tags=debian
when: ansible_distribution_major_version == "18"
- include: ubuntu20.yml tags=debian
when: ansible_distribution_major_version == "20"
- include: centos7.yml tags=centos
when: ansible_distribution_major_version == "7"
---
- name: create the node_exporter account
user:
create_home: false
name: node_exporter
shell: '/bin/false'
- name: check if node_exporter is already installed
stat:
path: /usr/local/bin/node_exporter
register: node_exporter_present_check
- name: set the fact that node_exporter is already installed
set_fact:
node_exporter_present: '{{ node_exporter_present_check.stat.exists }}'
- name: calculate the hash of the node_exporter binary
shell: sha256sum /usr/local/bin/node_exporter | awk '{split($0,a," "); print a[1];}'
register: node_exporter_hash
when: node_exporter_present
changed_when: false
- name: set the fact with the hash of the node_exporter binary
set_fact:
node_exporter_hash: node_exporter_hash.stdout_lines[0]
when: node_exporter_present
- name: set a dummy hash for the node_exporter binary
set_fact:
node_exporter_hash: 'dummy'
when: not node_exporter_present
- name: set the fact if hash is different from the pre-calculated one
set_fact:
node_exporter_hash_changed: "{{ node_exporter_hash != 'a39a9313b0f075a0f62e76e3c0cb85fd6f70f51175ee62a7bf107012a0e57f37' }}"
changed_when: false
- name: unpack node_exporter
unarchive:
remote_src: yes
src: https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
dest: /tmp
when: node_exporter_hash_changed
- name: move the node_exporter to the final destination
copy:
dest: /usr/local/bin/node_exporter
src: /tmp/node_exporter-0.18.1.linux-amd64/node_exporter
owner: node_exporter
group: node_exporter
mode: 'u+x'
remote_src: yes
when: node_exporter_hash_changed
- name: deploy the service definition file
template:
dest: /etc/systemd/system/node_exporter.service
src: node_exporter.service
- name: deploy additional service options config file
template:
dest: /etc/nodeexport.conf
src: nodeexport.conf
- name: reload systemd to take the new service into account
systemd:
daemon_reload: yes
enabled: yes
name: node_exporter
state: started
---
- name: create the node_exporter account
user:
create_home: false
name: node_exporter
shell: '/bin/false'
- name: check if node_exporter is already installed
stat:
path: /usr/local/bin/node_exporter
register: node_exporter_present_check
- name: set the fact that node_exporter is already installed
set_fact:
node_exporter_present: '{{ node_exporter_present_check.stat.exists }}'
- name: calculate the hash of the node_exporter binary
shell: sha256sum /usr/local/bin/node_exporter | awk '{split($0,a," "); print a[1];}'
register: node_exporter_hash
when: node_exporter_present
changed_when: false
- name: set the fact with the hash of the node_exporter binary
set_fact:
node_exporter_hash: node_exporter_hash.stdout_lines[0]
when: node_exporter_present
- name: set a dummy hash for the node_exporter binary
set_fact:
node_exporter_hash: 'dummy'
when: not node_exporter_present
- name: set the fact if hash is different from the pre-calculated one
set_fact:
node_exporter_hash_changed: "{{ node_exporter_hash != 'a39a9313b0f075a0f62e76e3c0cb85fd6f70f51175ee62a7bf107012a0e57f37' }}"
changed_when: false
- name: unpack node_exporter
unarchive:
remote_src: yes
src: https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
dest: /tmp
when: node_exporter_hash_changed
- name: move the node_exporter to the final destination
copy:
dest: /usr/local/bin/node_exporter
src: /tmp/node_exporter-0.18.1.linux-amd64/node_exporter
owner: node_exporter
group: node_exporter
mode: 'u+x'
remote_src: yes
when: node_exporter_hash_changed
- name: deploy the service definition file
template:
dest: /etc/systemd/system/node_exporter.service
src: node_exporter.service
- name: deploy additional service options config file
template:
dest: /etc/nodeexport.conf
src: nodeexport.conf
- name: reload systemd to take the new service into account
systemd:
daemon_reload: yes
enabled: yes
name: node_exporter
state: started
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
EnvironmentFile=/etc/nodeexport.conf
ExecStart=/usr/local/bin/node_exporter $ARG1 $ARG2 $ARG3 $ARG5 $ARG6 $ARG7
[Install]
WantedBy=multi-user.target
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
EnvironmentFile=/etc/nodeexport.conf
ExecStart=/usr/sbin/node_exporter $ARG1 $ARG2 $ARG3 $ARG5 $ARG6 $ARG7
[Install]
WantedBy=multi-user.target
ARG1=--collector.mountstats
ARG2=--collector.logind
ARG3=--collector.processes
ARG5=--collector.systemd
ARG6=--collector.tcpstat
ARG7=--collector.textfile.directory=/run/prometheus
---
- hosts: localhost
remote_user: root
roles:
- prometheus_node_exporter
\ No newline at end of file
---
# vars file for prometheus_node_exporter
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment