Skip to content

Commit

Permalink
Use variables from ansible_facts in _common role
Browse files Browse the repository at this point in the history
to allow ANSIBLE_INJECT_FACT_VARS to become false
  • Loading branch information
kleini committed Nov 21, 2024
1 parent ae73776 commit 5056013
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions roles/node_exporter/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
node_exporter_version: 1.8.2
node_exporter_binary_url: "https://github.com/{{ _node_exporter_repo }}/releases/download/v{{ node_exporter_version }}/\
node_exporter-{{ node_exporter_version }}.{{ ansible_system | lower }}-{{ _node_exporter_go_ansible_arch }}.tar.gz"
node_exporter-{{ node_exporter_version }}.{{ ansible_facts['system'] | lower }}-{{ _node_exporter_go_ansible_arch }}.tar.gz"
node_exporter_checksums_url: "https://github.com/{{ _node_exporter_repo }}/releases/download/v{{ node_exporter_version }}/sha256sums.txt"

node_exporter_web_disable_exporter_metrics: false
Expand Down Expand Up @@ -32,4 +32,4 @@ node_exporter_system_user: "{{ node_exporter_system_group }}"

node_exporter_config_dir: "/etc/node_exporter"
# Local path to stash the archive and its extraction
node_exporter_local_cache_path: "/tmp/node_exporter-{{ ansible_system | lower }}-{{ _node_exporter_go_ansible_arch }}/{{ node_exporter_version }}"
node_exporter_local_cache_path: "/tmp/node_exporter-{{ ansible_facts['system'] | lower }}-{{ _node_exporter_go_ansible_arch }}/{{ node_exporter_version }}"
4 changes: 2 additions & 2 deletions roles/node_exporter/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ argument_specs:
default: "1.8.2"
node_exporter_binary_url:
description: "URL of the node exporter binaries .tar.gz file"
default: "https://github.com/{{ _node_exporter_repo }}/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.{{ ansible_system | lower }}-{{ _node_exporter_go_ansible_arch }}.tar.gz"
default: "https://github.com/{{ _node_exporter_repo }}/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.{{ ansible_facts['system'] | lower }}-{{ _node_exporter_go_ansible_arch }}.tar.gz"
node_exporter_checksums_url:
description: "URL of the node exporter checksums file"
default: "https://github.com/{{ _node_exporter_repo }}/releases/download/v{{ node_exporter_version }}/sha256sums.txt"
Expand Down Expand Up @@ -78,7 +78,7 @@ argument_specs:
default: "node-exp"
node_exporter_local_cache_path:
description: "Local path to stash the archive and its extraction"
default: "/tmp/node_exporter-{{ ansible_system | lower }}-{{ _node_exporter_go_ansible_arch }}/{{ node_exporter_version }}"
default: "/tmp/node_exporter-{{ ansible_facts['system'] | lower }}-{{ _node_exporter_go_ansible_arch }}/{{ node_exporter_version }}"
node_exporter_config_dir:
description: "Path to directory with node_exporter configuration"
default: "/etc/node_exporter"
2 changes: 1 addition & 1 deletion roles/node_exporter/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
tasks_from: selinux.yml
vars:
_common_selinux_port: "{{ node_exporter_web_listen_address | urlsplit('port') }}"
when: ansible_selinux.status == "enabled"
when: ansible_facts['selinux'].status == "enabled"
tags:
- node_exporter_configure

Expand Down
2 changes: 1 addition & 1 deletion roles/node_exporter/templates/node_exporter.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RestartSec=1
StartLimitInterval=0

{% set ns = namespace(protect_home = 'yes') %}
{% for m in ansible_mounts if m.mount.startswith('/home') %}
{% for m in ansible_facts['mounts'] if m.mount.startswith('/home') %}
{% set ns.protect_home = 'read-only' %}
{% endfor %}
{% if node_exporter_textfile_dir.startswith('/home') %}
Expand Down
2 changes: 1 addition & 1 deletion roles/node_exporter/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ _node_exporter_go_ansible_arch: "{{ {'i386': '386',
'x86_64': 'amd64',
'aarch64': 'arm64',
'armv7l': 'armv7',
'armv6l': 'armv6'}.get(ansible_architecture, ansible_architecture) }}"
'armv6l': 'armv6'}.get(ansible_facts['architecture'], ansible_facts['architecture']) }}"
_node_exporter_repo: "prometheus/node_exporter"
_github_api_headers: "{{ {'GITHUB_TOKEN': lookup('ansible.builtin.env', 'GITHUB_TOKEN')} if (lookup('ansible.builtin.env', 'GITHUB_TOKEN')) else {} }}"
_node_exporter_binaries: ['node_exporter']

0 comments on commit 5056013

Please sign in to comment.