|
1 | 1 | ---
|
2 |
| -- include: preflight.yml |
3 |
| - |
4 |
| -- name: Create the Node Exporter group |
5 |
| - group: |
6 |
| - name: "node-exp" |
7 |
| - state: present |
8 |
| - system: true |
9 |
| - |
10 |
| -- name: Create the Node Exporter user |
11 |
| - user: |
12 |
| - name: "node-exp" |
13 |
| - groups: "node-exp" |
14 |
| - append: true |
15 |
| - shell: /usr/sbin/nologin |
16 |
| - system: true |
17 |
| - createhome: false |
18 |
| - home: / |
19 |
| - |
20 |
| -- name: Download node_exporter binary to local folder |
21 |
| - become: false |
22 |
| - get_url: |
23 |
| - url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz" |
24 |
| - dest: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz" |
25 |
| - checksum: "sha256:{{ node_exporter_checksum }}" |
26 |
| - register: _download_binary |
27 |
| - until: _download_binary is succeeded |
28 |
| - retries: 5 |
29 |
| - delay: 2 |
30 |
| - delegate_to: localhost |
31 |
| - check_mode: false |
32 |
| - |
33 |
| -- name: Unpack node_exporter binary |
34 |
| - become: false |
35 |
| - unarchive: |
36 |
| - src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}.tar.gz" |
37 |
| - dest: "/tmp" |
38 |
| - creates: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/node_exporter" |
39 |
| - delegate_to: localhost |
40 |
| - check_mode: false |
41 |
| - |
42 |
| -- name: Propagate Node Exporter binaries |
43 |
| - copy: |
44 |
| - src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}/node_exporter" |
45 |
| - dest: "/usr/local/bin/node_exporter" |
46 |
| - mode: 0750 |
47 |
| - owner: "node-exp" |
48 |
| - group: "node-exp" |
49 |
| - notify: |
50 |
| - - restart node exporter |
51 |
| - when: not ansible_check_mode |
52 |
| - |
53 |
| -- name: Create texfile collector dir |
54 |
| - file: |
55 |
| - path: "{{ node_exporter_textfile_dir }}" |
56 |
| - state: directory |
57 |
| - owner: "node-exp" |
58 |
| - group: "node-exp" |
59 |
| - recurse: true |
60 |
| - mode: 0755 |
61 |
| - when: node_exporter_textfile_dir != "" |
62 |
| - |
63 |
| -- name: Install libcap on Debian systems |
64 |
| - package: |
65 |
| - name: "libcap2-bin" |
66 |
| - state: present |
67 |
| - when: ansible_os_family | lower == "debian" |
68 |
| - |
69 |
| -- name: Node exporter can read anything (omit file permissions) |
70 |
| - capabilities: |
71 |
| - path: '/usr/local/bin/node_exporter' |
72 |
| - capability: cap_dac_read_search+ep |
73 |
| - state: present |
74 |
| - when: |
75 |
| - not ansible_check_mode |
76 |
| - |
77 |
| -- name: Copy the Node Exporter systemd service file |
78 |
| - template: |
79 |
| - src: node_exporter.service.j2 |
80 |
| - dest: /etc/systemd/system/node_exporter.service |
81 |
| - owner: root |
82 |
| - group: root |
83 |
| - mode: 0644 |
84 |
| - notify: |
85 |
| - - restart node exporter |
86 |
| - |
87 |
| -- name: Install dependencies on RedHat OS family |
88 |
| - package: |
89 |
| - name: "{{ item }}" |
90 |
| - state: present |
91 |
| - with_items: |
92 |
| - - libselinux-python |
93 |
| - - policycoreutils-python |
94 |
| - when: |
95 |
| - - ansible_os_family == "RedHat" |
96 |
| - |
97 |
| -- name: Allow Node Exporter port in SELinux on RedHat OS family |
98 |
| - seport: |
99 |
| - ports: "{{ node_exporter_web_listen_address.split(':')[1] }}" |
100 |
| - proto: tcp |
101 |
| - setype: http_port_t |
102 |
| - state: present |
103 |
| - when: |
104 |
| - - ansible_version.full is version_compare('2.4', '>=') |
105 |
| - - ansible_selinux.status == "enabled" |
| 2 | +- name: Gather variables for each operating system |
| 3 | + include_vars: "{{ item }}" |
| 4 | + with_first_found: |
| 5 | + - "{{ ansible_distribution | lower }}.yml" |
| 6 | + - "{{ ansible_os_family | lower }}.yml" |
| 7 | + tags: |
| 8 | + - always |
| 9 | + |
| 10 | +- import_tasks: preflight.yml |
| 11 | + tags: |
| 12 | + - always |
| 13 | + |
| 14 | +- import_tasks: install.yml |
| 15 | + become: true |
| 16 | + tags: |
| 17 | + - install |
| 18 | + |
| 19 | +- import_tasks: configure.yml |
| 20 | + become: true |
| 21 | + tags: |
| 22 | + - configure |
106 | 23 |
|
107 | 24 | - name: Ensure Node Exporter is enabled on boot
|
| 25 | + become: true |
108 | 26 | systemd:
|
109 | 27 | name: node_exporter
|
110 | 28 | enabled: true
|
| 29 | + tags: |
| 30 | + - run |
0 commit comments