Giter Club home page Giter Club logo

ansible-role-node_exporter's Introduction

Ansible Role: Node exporter

CI

This role installs Prometheus' Node exporter on Linux hosts, and configures a systemd unit file so the service can run and be controlled by systemd.

Note: If you're running in a Kubernetes cluster, you could run Node exporter as a DaemonSet in the cluster, instead of installing it on individual nodes.

Requirements

N/A

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml):

node_exporter_version: '0.18.1'

The version of Node exporter to install. Available releases can be found on the tags listing in the Node exporter repository. Drop the v off the tag.

If you change the version, the node_exporter binary will be replaced with the updated version, and the service will be restarted.

node_exporter_arch: 'amd64'
node_exporter_download_url: https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-{{ node_exporter_arch }}.tar.gz

The architecture and download URL for Node exporter. If you're on a Raspberry Pi running Raspbian, you may need to override the arch value with armv7.

node_exporter_bin_path: /usr/local/bin/node_exporter

The path where the node_exporter binary will be installed.

node_exporter_host: 'localhost'
node_exporter_port: 9100

Host and port on which node exporter will listen.

node_exporter_options: ''

Any additional options to pass to node_exporter when it starts, e.g. --no-collector.wifi if you want to ignore any WiFi data.

node_exporter_state: started
node_exporter_enabled: true

Controls for the node_exporter service.

Dependencies

None.

Example Playbook

- hosts: all
  roles:
    - role: geerlingguy.node_exporter

License

MIT / BSD

Author Information

This role was created in 2020 by Jeff Geerling, author of Ansible for DevOps.

ansible-role-node_exporter's People

Contributors

automoto avatar cschlesselmann avatar danielweeber avatar dweebertwt avatar geerlingguy avatar michaeldelago avatar tmgstevens avatar tzermias avatar xr09 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ansible-role-node_exporter's Issues

Wrong usage of is success on Move node_exporter binary into place

Hi,

When Download and unarchive node_exporter into temporary location is skipped, Move node_exporter binary into place is still executed because a skipped task still counts as success. See ansible/ansible#25027 (comment) for reference.

This causes the Move node_exporter binary into place task to fail if the download job was skipped and the temporary file doesn't exist anymore.

PLAY [all] *************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [host.example.org]

TASK [geerlingguy.node_exporter : Check current node_exporter version.] ************************************************
ok: [host.example.org]

TASK [geerlingguy.node_exporter : Download and unarchive node_exporter into temporary location.] ***********************
skipping: [host.example.org]

TASK [geerlingguy.node_exporter : Move node_exporter binary into place.] ***********************************************
fatal: [host.example.org]: FAILED! => {"changed": false, "msg": "Source /tmp/node_exporter-1.3.1.linux-amd64/node_exporter not found"}

add option to not check if exporter is up

I am using packer to make an image that includes the node exporter in a chroot, therefore the liveness check at the end is failing. Please consider adding an option to skip this check.

Problem with verify task and node_exporter_host variable

Referring to this task:

- name: Verify node_exporter is responding to requests.

There are some issues around this check and the node_exporter_host variable. I can PR a fix, but want to think a little more what the best option to offer is.

The role's current default is to use localhost. One issue is that localhost will make node_exporter only listen on IPv4. If no --web.listen-address option is specified, the default is actually ":9100" (so an empty hostname and will listen on all interfaces):

ts=2022-08-31T02:23:56.106Z caller=node_exporter.go:199 level=info msg="Listening on" address=:9100

and this also listens on IPv4 and IPv6 (notice the tcp6 and :::9100 listener):

$ netstat -an | grep 9100
tcp6       0      0 :::9100                 :::*                    LISTEN    

Specifying the empty string for node_exporter_host will make the uri check in this task fail as http://:9100/ is not valid. Other valid example of --web.listen-address options are:

  • --web.listen-address=0.0.0.0:9100. # alternate way to specify "listen on all interfaces"
  • --web.listen-address='[::1]:9100' # Listen on IPv6 & IPv4 localhost

Maybe an easy workaround is to provide a role variable that makes this check optional?

Detect architecture at runtime

Setting the package architecture at runtime, instead of defining it in a variable, might make the role easier to use. If you're interested, I can make a pull request for this feature.

Make the node_exporter user a system user

In certain environments you can have users created with specific UIDs.
By setting the node_exporter user as system: true. It will use a dynamic
system uid instead.

Node exporter release checksum verification

Is it possible to implement checksum verification for node exporter releases? Perhaps not by default but optionally in case users want to define an explicit version or use a custom value for node_exporter_download_url.

If considered a good idea, I can see if I can make a simple implementation of this feature.

Status code was -1 and not [200]: Connection failure: timed out

Hi, I get this error

TASK [ansible-role-node_exporter : Verify node_exporter is responding to requests.] *******************************************************************************************************************************************************fatal: [mobile-admin.backend.ab.internal]: FAILED! => {"changed": false, "content": "", "elapsed": 30, "failed_when_result": true, "msg": "Status code was -1 and not [200]: Connection failure: timed out", "redirected": false, "status": -1, "url": "http://localhost:9100/"}
If I do restart node_exporter on the target server, the error does not appear after that

Changing the node_exporter_options as no effect unless the package also changes and left over packages cause other issues

2 Issues..

Issue (1) ..Changing the node_options_does not get picked up unless we change the version

Steps To Reproduce

  • Install version 1.6.1 of node-exporter
 - role: geerlingguy.node_exporter
      tags: node_exporter
      vars:
        node_exporter_version: 1.6.1
        node_exporter_options: '--collector.systemd"'
  • Change the node_exporter_options
 - role: geerlingguy.node_exporter
      tags: node_exporter
      vars:
        node_exporter_version: 1.6.1
        node_exporter_options: '--collector.textfile.directory=/var/lib/node_exporter/textfile_collector --collector.systemd"'
  • Rerun the playbook - the new options do not get pickedup

A workaround is to downgrade to 1.6.0 deploy to pick up the new node_exporter_options, and then redeploy 1.61.

However this leaves package 1.6.0 on disk in the /tmp folder so the redeployment is skipped leaving you with 1.6.0

  • Removing the downloaded packages from /tmp allows you to redeploy v1.6.1 again

Version details output to 'stderr'.

I use ansible==2.9.11.

I don't know since which version of node_exporter this is the case, but when using this role with version 1.1.2 the version details retrieved are written to stderr instead of stdout.

This results in always running the subsequent task ( Download and unarchive node_exporter into temporary location.) with the condition:

when: >
node_exporter_version_check.stdout is not defined
or node_exporter_version not in node_exporter_version_check.stdout

Also, the above condition is missing in task Move node_exporter binary into place. When nothing is downloaded to /tmp the folder won't be found with copy.

"Determine latest GitHub release" is causing an unbalanced number of tasks

The task of "Determine latest GitHub release" that delegates the call to localhost is causing an unbalanced number of tasks.
e.g.
PLAY RECAP *********************************************************************
influxdb.themachine.art : ok=21 changed=0 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0
prometheus.themachine.art : ok=22 changed=0 unreachable=0 failed=0 skipped=3 rescued=0 ignored=0

you can see that influxdb.themachine.art only has 21 oks as opposed to prometheus.themachine.art that has 22
it causes an ambiguity and uncertainty, it is also preventing me from running automations to check that ansible is running properly.

is it possible to have a configuration where I choose not to delegate to localhost or even not to run this task at all?

Thanks,
Roy

Possible `vars_files` collision?

Hello! I am relatively new to Ansible.

In my playbook:

---
- name: Install node_exporter
  hosts: local
  vars_files:
    - "{{ inventory_dir }}/vars/vars.yaml"
  become: true

  roles:
  - role: geerlingguy.node_exporter

I store vars_files in "{{ inventory_dir }}/vars/vars.yaml" path. The file is encrypted and instantly decrypted on any playbook run via .vault_password.txt file which contain password to decrypt vars,yaml file.

Using your role gives error:

fatal: [<SOME IP ADDRESS> -> localhost]: FAILED! => {
    "msg": "'root_password' is undefined"
}

I checked logs with -vvv option when launch the playbook, and found behaviour that is strange for me:

TASK [geerlingguy.node_exporter : Configure latest version] **************************************
task path: /home/<SOME USER>/.ansible/roles/geerlingguy.node_exporter/tasks/main.yml:8
Read vars_file '{{ inventory_dir }}/vars/vars.yaml'
included: /home/<SOME USER>/.ansible/roles/geerlingguy.node_exporter/tasks/config-version.yaml for <SOME IP ADDRESS>
skipping vars_file '{{ inventory_dir }}/vars/vars.yaml' due to an undefined variable
Read vars_file '{{ inventory_dir }}/vars/vars.yaml'
skipping vars_file '{{ inventory_dir }}/vars/vars.yaml' due to an undefined variable

TASK [geerlingguy.node_exporter : Determine latest GitHub release (local)] ***********************
task path: /home/<SOME USER>/.ansible/roles/geerlingguy.node_exporter/tasks/config-version.yaml:2
fatal: [<SOME IP ADDRESS> -> localhost]: FAILED! => {
    "msg": "'root_password' is undefined"
}

While other playbooks catch variables file correctly, this one does not when using your role.

Where is the problem, exactly?

Installation failure

My playbook has just this

- role: geerlingguy.node_exporter

I've not overridden any of the default variable values.

Installation fails with

TASK [geerlingguy.node_exporter : Check current node_exporter version.] **********************************************************************************************************************************************************************
ok: [---removed---] => {"changed": false, "cmd": "/usr/local/bin/node_exporter --version", "failed_when_result": false, "msg": "[Errno 2] No such file or directory: b'/usr/local/bin/node_exporter'", "rc": 2, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

TASK [geerlingguy.node_exporter : Download and unarchive node_exporter into temporary location.] *********************************************************************************************************************************************
ok: [---removed---] => {"changed": false, "dest": "/tmp", "gid": 0, "group": "root", "handler": "TgzArchive", "mode": "01777", "owner": "root", "size": 4096, "src": "/home/talonx/.ansible/tmp/ansible-tmp-1679037032.2916012-18457-279738429074661/node_exporter-0.16.0.linux-amd64.tarwia9p17m.gz", "state": "directory", "uid": 0}

TASK [geerlingguy.node_exporter : Move node_exporter binary into place.] *********************************************************************************************************************************************************************
fatal: [---removed---]: FAILED! => {"changed": false, "msg": "Source /tmp/node_exporter-0.18.1.linux-amd64/node_exporter not found"}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
---removed---               : ok=3    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

It seems to be attempting to download 0.16.0 but trying to unpack 0.18.1

NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Ansible role version is 1.0.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.