Ansible Playbook部署node_exporter
1.新建ansible playbook roles
# 进入ansible roles目录
cd /etc/ansible/roles
# 初始化
ansible-galaxy init deploy_node_exporter
# 下载node_exporter
cd deploy_node_exporter/files
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
# 目录结构
tree deploy_node_exporter/
deploy_node_exporter/
├── defaults
│ └── main.yml
├── files
│ └── node_exporter-0.18.1.linux-amd64.tar.gz
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── README.md
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.yml
---
- name: create directory /ops
file:
path: /ops
state: directory
mode: '0755'
- name: unarchive node_exporter
unarchive:
src: node_exporter-0.18.1.linux-amd64.tar.gz
dest: /ops/
- name: configure node_exporter.service
lineinfile:
path: /usr/lib/systemd/system/node_exporter.service
line: "{{ item }}"
create: yes
state: present
with_items:
- "[Unit]"
- "Description=Node Exporter For Prometheus"
- "[Service]"
- "Type=simple"
- "ExecStart=/ops/node_exporter-0.18.1.linux-amd64/node_exporter"
- "[Install]"
- "WantedBy=mutil-user.target"
- name: start and enable service
shell: |
systemctl daemon-reload
systemctl enable node_exporter
systemctl start node_exporter
- name: add firewall port 9100
shell: firewall-cmd --add-port=9100/tcp --permanent && firewall-cmd --reload
---
- hosts: node01
remote_user: root
roles:
- deploy_node_exporter
ansible-playbook deploy_node_exporter.yml
curl http://node01:9100/metrics