반응형
node_exporter를 설치하는 playbook 파일은 앞선 prometheus설치한 디렉토리에 node-exporter 라는 Role을 추가하여 작성하였습니다.
그래서 ansible-prometheus github에서 다운받을 수 있습니다.
https://github.com/hkjeon/ansible-prometheus
## 환경 정보
node_exporter : xx.xx.xx.4 (RHEL 8.4 / kvmhost)
ansible-controller : xx.xx.xx.5 (RHEL 8.4)
prometheus : xx.xx.xx.6 (RHEL 8.4)
1. node-exporter-main.yml 생성
[root@hk-controller ansible-prometheus]#cat node-exporter-main.yaml
---
- hosts: node-exporter
become: false
gather_facts: false
roles:
- node-exporter
2. install roles 생성
ansible-galaxy init roles/node-exporter
3. role에서 사용할 변수 내용 구성
[root@hk-controller defaults]#cat main.yml
---
# defaults file for roles/node-exporter
node_exporter_version: 1.2.2
node_exporter_binary_install_dir: '/usr/local/bin'
4. templates 파일 구성 (systemd용)
[root@hk-controller templates]#cat node_exporter.systemd.j2
[Unit]
Description=Prometheus Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
5. task 작성
[root@hk-controller tasks]#cat main.yml
# tasks file for roles/node_exporter
---
- name: create node_exporter system group
group:
name: node_exporter
system: true
state: present
- name: node_exporter User add
user:
name: node_exporter
system: true
shell: "/usr/sbin/nologin"
group: node_exporter
createhome: false
- block:
- name: download node_exporter package to localhost
become: false
get_url:
url: "https://github.com/prometheus/node_exporter/releases/download/v{{ node_exporter_version }}/node_exporter-{{ node_exporter_version }}.linux-amd64.tar.gz"
dest: "/tmp/node_exporter-{{ node_exporter_version }}.linux-amd64.tar.gz"
- name: unpack node_exporter binaries
unarchive:
src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-amd64.tar.gz"
dest: "/tmp"
remote_src: yes
- name: copy node_exporter and promtool binaries files
copy:
src: "/tmp/node_exporter-{{ node_exporter_version }}.linux-amd64/{{ item }}"
dest: "{{ node_exporter_binary_install_dir }}/{{ item }}"
mode: 0755
owner: root
group: root
remote_src: yes
with_items:
- node_exporter
- name: Configuration systemd Files for node_exporter
template:
src: node_exporter.systemd.j2
dest: /etc/systemd/system/node_exporter.service
owner: root
group: root
mode: 0644
notify:
- restart node_exporter
- name: reload for node_exporter
systemd:
name: node_exporter
enabled: true
state: started
6. handler 작성
[root@hk-controller handlers]#cat main.yml
---
# handlers file for roles/node-exporter
- name: restart node_exporter
become: true
systemd:
daemon_reload: true
name: node_exporter
state: restarted
7. hosts에 node-exporter host 추가
[root@hk-controller ansible-prometheus]#pwd
/root/ansible-playbook/prometheus/ansible-prometheus
[root@hk-controller ansible-prometheus]#cat hosts
[prometheus]
xx.xx.xx.6
[node-exporter]
xx.xx.xx.4
8. 실행방법
[root@hk-controller ansible-prometheus]#ansible-playbook node-exporter-main.yaml
728x90
'IaC (Automation) > Ansible-Playbook' 카테고리의 다른 글
[playbook] kvm (virt-manager) 설치 playbook (0) | 2021.10.13 |
---|---|
[playbook] grafana 설치 playbook (0) | 2021.10.08 |
[playbook] Prometheus 설치 playbook (0) | 2021.10.08 |
[Ansible] import vs include 차이점 (0) | 2021.07.29 |
[Ansible] AWS and Openstack Modules (0) | 2021.07.28 |