ansible_tools/prometheus/roles/node_exporter/tasks/main.yml

60 lines
1.4 KiB
YAML
Raw Permalink Normal View History

---
# 校验 Node Exporter 是否安装
- name: '<{{ cmd | upper }}> | 校验 Node Exporter 是否安装'
stat:
path: '{{ flag }}'
register: ret
# 安装 Node Exporter
- block:
- name: '<{{ cmd | upper }}> | 创建 Node Exporter 相关目录'
file:
path: '{{ node_exporter.dir }}'
state: directory
- name: '<{{ cmd | upper }}> | 安装 Node Exporter'
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- src: docker-compose.yml.j2
dest: '{{ node_exporter.dir }}/docker-compose.yml'
- name: '<{{ cmd | upper }}> | 启动 Node Exporter 容器'
shell: |
. /etc/profile
cd {{ node_exporter.dir }}
docker-compose down
docker-compose up -d
- name: '<{{ cmd | upper }}> | 等待 Node Exporter 服务启动'
wait_for:
port: '{{ node_exporter.port }}'
- name: '<{{ cmd | upper }}> | 创建 Node Exporter 安装标记'
shell: |
set -ex
mkdir -p ~/.flag
touch {{ flag }}
when:
- cmd == "install"
- not ret.stat.exists
# 卸载 Node Exporter
- block:
- name: '<{{ cmd | upper }}> | 卸载 Node Exporter'
shell: |
. /etc/profile
cd {{ node_exporter.dir }}
docker-compose down
- name: '<{{ cmd | upper }}> | 清除 Node Exporter 相关文件'
shell: |
rm -rf {{ node_exporter.dir }}
rm -rf {{ flag }}
when:
- cmd == "remove"
- ret.stat.exists