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